seo_cache 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +4 -0
 - data/lib/seo_cache/middleware.rb +14 -3
 - data/lib/seo_cache/page_caching.rb +12 -12
 - data/lib/seo_cache/populate_cache.rb +1 -1
 - data/lib/seo_cache/version.rb +1 -1
 - data/lib/seo_cache.rb +6 -0
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 959dca2a3a9df2edb1bf3b7ff01e09a5632fb572624d101acc46a2a773f1de4f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 176b714c37870807890538accd50b47849c42702e734fb0124841dc6df870296
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 433a9a7f97517d4c8e2b1335997c0d7de7c41044a51f8c90e3439ea07e92b4174986233e3ead7a72dd7a117674fc3b2d2cce2eab162776867e4afe5b8dafe3b6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 93e2d478189c54928bd6adeaa48aca393b96f1a5b5807bd44019880a9808d78e97e633fcdfe4a13bf5379faccbbfa373491a4f372607637e4de2468edb250594
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/seo_cache/middleware.rb
    CHANGED
    
    | 
         @@ -186,7 +186,9 @@ module SeoCache 
     | 
|
| 
       186 
186 
     | 
    
         
             
                  # return nil unless @options[:before_render]
         
     | 
| 
       187 
187 
     | 
    
         
             
                  # cached_render = @options[:before_render].call(env)
         
     | 
| 
       188 
188 
     | 
    
         | 
| 
       189 
     | 
    
         
            -
                   
     | 
| 
      
 189 
     | 
    
         
            +
                  env_request = Rack::Request.new(env)
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
                  cached_render = @page_caching.get(env_request.path, get_locale(env_request.params, env_request.host))
         
     | 
| 
       190 
192 
     | 
    
         | 
| 
       191 
193 
     | 
    
         
             
                  return nil unless cached_render
         
     | 
| 
       192 
194 
     | 
    
         | 
| 
         @@ -213,12 +215,21 @@ module SeoCache 
     | 
|
| 
       213 
215 
     | 
    
         
             
                def after_render(env, response, status = 200)
         
     | 
| 
       214 
216 
     | 
    
         
             
                  return unless response && SeoCache.cache_only_status.include?(status.to_i)
         
     | 
| 
       215 
217 
     | 
    
         | 
| 
      
 218 
     | 
    
         
            +
                  env_request = Rack::Request.new(env)
         
     | 
| 
      
 219 
     | 
    
         
            +
             
     | 
| 
       216 
220 
     | 
    
         
             
                  if SeoCache.log_missed_cache
         
     | 
| 
       217 
     | 
    
         
            -
                    env_request = Rack::Request.new(env)
         
     | 
| 
       218 
221 
     | 
    
         
             
                    SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})")
         
     | 
| 
       219 
222 
     | 
    
         
             
                  end
         
     | 
| 
       220 
223 
     | 
    
         | 
| 
       221 
     | 
    
         
            -
                  @page_caching.cache(response,  
     | 
| 
      
 224 
     | 
    
         
            +
                  @page_caching.cache(response, env_request.path, get_locale(env_request.params, env_request.host))
         
     | 
| 
      
 225 
     | 
    
         
            +
                end
         
     | 
| 
      
 226 
     | 
    
         
            +
             
     | 
| 
      
 227 
     | 
    
         
            +
                def get_locale(params, host)
         
     | 
| 
      
 228 
     | 
    
         
            +
                  if SeoCache.locale_as_first_directory
         
     | 
| 
      
 229 
     | 
    
         
            +
                    SeoCache.locale_method ? SeoCache.locale_method.call(params, host) : I18n.locale
         
     | 
| 
      
 230 
     | 
    
         
            +
                  else
         
     | 
| 
      
 231 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 232 
     | 
    
         
            +
                  end
         
     | 
| 
       222 
233 
     | 
    
         
             
                end
         
     | 
| 
       223 
234 
     | 
    
         
             
              end
         
     | 
| 
       224 
235 
     | 
    
         
             
            end
         
     | 
| 
         @@ -13,31 +13,31 @@ module SeoCache 
     | 
|
| 
       13 
13 
     | 
    
         
             
                  @redis = Redis::Namespace.new(SeoCache.redis_namespace, redis: Redis.new(host: uri.host, port: uri.port, password: uri.password, connect_timeout: 1, timeout: 1), warnings: false)
         
     | 
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                def get(path, extension = nil)
         
     | 
| 
       17 
     | 
    
         
            -
                  @redis.get(cache_path(path, extension)) if SeoCache.memory_cache? && @redis
         
     | 
| 
      
 16 
     | 
    
         
            +
                def get(path, locale_domain = nil, extension = nil)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @redis.get(cache_path(path, locale_domain, extension)) if SeoCache.memory_cache? && @redis
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                def cache(content, path, locale_domain = nil, extension = nil, gzip = Zlib::BEST_COMPRESSION)
         
     | 
| 
       21 
21 
     | 
    
         
             
                  instrument :write_page, path do
         
     | 
| 
       22 
22 
     | 
    
         
             
                    if SeoCache.memory_cache? && @redis
         
     | 
| 
       23 
     | 
    
         
            -
                      write_to_memory(content, cache_path(path,  
     | 
| 
      
 23 
     | 
    
         
            +
                      write_to_memory(content, cache_path(path, locale_domain, extension))
         
     | 
| 
       24 
24 
     | 
    
         
             
                    else
         
     | 
| 
       25 
     | 
    
         
            -
                      write_to_disk(content, cache_path(path,  
     | 
| 
      
 25 
     | 
    
         
            +
                      write_to_disk(content, cache_path(path, locale_domain, extension), gzip)
         
     | 
| 
       26 
26 
     | 
    
         
             
                    end
         
     | 
| 
       27 
27 
     | 
    
         
             
                  end
         
     | 
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                def expire(path)
         
     | 
| 
      
 30 
     | 
    
         
            +
                def expire(path, locale_domain = nil, extension = nil)
         
     | 
| 
       31 
31 
     | 
    
         
             
                  instrument :expire_page, path do
         
     | 
| 
       32 
     | 
    
         
            -
                    delete(cache_path(path))
         
     | 
| 
      
 32 
     | 
    
         
            +
                    delete(cache_path(path, locale_domain, extension))
         
     | 
| 
       33 
33 
     | 
    
         
             
                  end
         
     | 
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                def cache_exists?(path)
         
     | 
| 
      
 36 
     | 
    
         
            +
                def cache_exists?(path, locale_domain = nil, extension = nil)
         
     | 
| 
       37 
37 
     | 
    
         
             
                  if SeoCache.memory_cache? && @redis
         
     | 
| 
       38 
     | 
    
         
            -
                    @redis.exists?(cache_path(path))
         
     | 
| 
      
 38 
     | 
    
         
            +
                    @redis.exists?(cache_path(path, locale_domain, extension))
         
     | 
| 
       39 
39 
     | 
    
         
             
                  else
         
     | 
| 
       40 
     | 
    
         
            -
                    File.exist?(cache_path(path))
         
     | 
| 
      
 40 
     | 
    
         
            +
                    File.exist?(cache_path(path, locale_domain, extension))
         
     | 
| 
       41 
41 
     | 
    
         
             
                  end
         
     | 
| 
       42 
42 
     | 
    
         
             
                end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
         @@ -51,7 +51,7 @@ module SeoCache 
     | 
|
| 
       51 
51 
     | 
    
         
             
                  SeoCache.cache_extension
         
     | 
| 
       52 
52 
     | 
    
         
             
                end
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
                def cache_file(path,  
     | 
| 
      
 54 
     | 
    
         
            +
                def cache_file(path, locale_domain, extension)
         
     | 
| 
       55 
55 
     | 
    
         
             
                  name = if path.empty? || path =~ %r{\A/+\z}
         
     | 
| 
       56 
56 
     | 
    
         
             
                           '/index'
         
     | 
| 
       57 
57 
     | 
    
         
             
                         else
         
     | 
| 
         @@ -65,8 +65,8 @@ module SeoCache 
     | 
|
| 
       65 
65 
     | 
    
         
             
                  name
         
     | 
| 
       66 
66 
     | 
    
         
             
                end
         
     | 
| 
       67 
67 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
                def cache_path(path,  
     | 
| 
       69 
     | 
    
         
            -
                  File.join(cache_directory, cache_file(path,  
     | 
| 
      
 68 
     | 
    
         
            +
                def cache_path(path, locale_domain = nil, extension = nil)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  File.join(cache_directory, cache_file(path, locale_domain, extension))
         
     | 
| 
       70 
70 
     | 
    
         
             
                end
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                def write_to_memory(content, path)
         
     | 
| 
         @@ -35,7 +35,7 @@ module SeoCache 
     | 
|
| 
       35 
35 
     | 
    
         
             
                private
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
                def generate_cache(path, locale_domain = nil)
         
     | 
| 
       38 
     | 
    
         
            -
                  return if @page_caching.cache_exists?(path) && !@force_cache
         
     | 
| 
      
 38 
     | 
    
         
            +
                  return if @page_caching.cache_exists?(path, nil, locale_domain) && !@force_cache
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
                  url = @host + path
         
     | 
| 
       41 
41 
     | 
    
         
             
                  url += path.include?('?') ? '&' : '?'
         
     | 
    
        data/lib/seo_cache/version.rb
    CHANGED
    
    
    
        data/lib/seo_cache.rb
    CHANGED
    
    | 
         @@ -22,6 +22,12 @@ module SeoCache 
     | 
|
| 
       22 
22 
     | 
    
         
             
              mattr_accessor :cache_path
         
     | 
| 
       23 
23 
     | 
    
         
             
              self.cache_path = ''
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
      
 25 
     | 
    
         
            +
              mattr_accessor :locale_as_first_directory
         
     | 
| 
      
 26 
     | 
    
         
            +
              self.locale_as_first_directory = false
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              mattr_accessor :locale_method
         
     | 
| 
      
 29 
     | 
    
         
            +
              self.locale_method = nil
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       25 
31 
     | 
    
         
             
              mattr_accessor :cache_extension
         
     | 
| 
       26 
32 
     | 
    
         
             
              self.cache_extension = '.html'
         
     | 
| 
       27 
33 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: seo_cache
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - FloXcoder
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2021-10- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-10-29 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rack
         
     | 
| 
         @@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       229 
229 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       230 
230 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       231 
231 
     | 
    
         
             
            requirements: []
         
     | 
| 
       232 
     | 
    
         
            -
            rubygems_version: 3.2. 
     | 
| 
      
 232 
     | 
    
         
            +
            rubygems_version: 3.2.30
         
     | 
| 
       233 
233 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       234 
234 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       235 
235 
     | 
    
         
             
            summary: Cache dedicated for SEO with Javascript rendering
         
     |