seo_cache 1.0.6 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 470c0f8bf9bee91e738987dd31618d612d4f8007fe5d486bce1c4d7c0f1053de
4
- data.tar.gz: cc0bb416f7893fb08a97e845635c374bf8dbc846127724077729d6870ceb93ec
3
+ metadata.gz: 1020870d044657759ac90591559df5abb82b9418ec242f6af3a8d100e457f593
4
+ data.tar.gz: 4627cb1b8e6ee8d0429c0d3ad61151670e85f881e6c0bc117ef67b2a08dfc1d8
5
5
  SHA512:
6
- metadata.gz: 6057c2afeb50daf1a93c1df0e9f6c90d55be66688445a417dca2d6b434d0dfc587e487be4d4404d3897c783f0e3d3d2880d5f9b6524b35975e5c87031028e4c2
7
- data.tar.gz: 5822d662fdbbf6d2c47bb21ed627697c52760e6133eff49978f11c3ad6fd984cb0b67c8b6e778e6bc43742a2ba2241bdf81d24f810333e92be60c840d159559c
6
+ metadata.gz: 0ea43ce22d924cfc142ffbcd6fc2d55989b46707c17a2fc210b5a1a31bbe6d9368c34990885a1bc476bc674145734f924fe006dad55cd2997f9a54747d4a1471
7
+ data.tar.gz: 61b1a6b1502c74cf0dff847ac8912018b47e9a295bc441d10c7641e3f31762e65186539477095cac2ec8f644d9d1d5f256b55c42d3526a4aff3c30633814a18a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 1.1.2
2
+
3
+ - Correct populate seo cache method
4
+
5
+ ## 1.1.1
6
+
7
+ - Add new option to use locale as first directory for cache path
8
+
9
+ ## 1.1.0
10
+
11
+ - Update dependencies
12
+
13
+ ## 1.0.7
14
+
15
+ - Use new syntax to check if Redis key exists
16
+
1
17
  ## 1.0.6
2
18
 
3
19
  - Logs only missed cache for success response
@@ -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
- cached_render = @page_caching.get(Rack::Request.new(env).path)
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, Rack::Request.new(env).path)
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, extension, locale_domain))
23
+ write_to_memory(content, cache_path(path, locale_domain, extension))
24
24
  else
25
- write_to_disk(content, cache_path(path, extension, locale_domain), gzip)
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, extension, locale_domain)
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, extension = nil, locale_domain = nil)
69
- File.join(cache_directory, cache_file(path, extension, locale_domain))
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, locale_domain) && !@force_cache
39
39
 
40
40
  url = @host + path
41
41
  url += path.include?('?') ? '&' : '?'
@@ -1,3 +1,3 @@
1
1
  module SeoCache
2
- VERSION = '1.0.6'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
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
 
data/seo_cache.gemspec CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'railties', '>= 5'
26
26
  spec.add_dependency 'redis', '~> 4'
27
27
  spec.add_dependency 'redis-namespace', '~> 1'
28
- spec.add_dependency 'selenium-webdriver', '~> 3'
29
- spec.add_dependency 'webdrivers', '~> 4'
28
+ spec.add_dependency 'selenium-webdriver', '>= 3'
29
+ spec.add_dependency 'webdrivers', '>= 3'
30
30
 
31
31
  spec.add_development_dependency 'bundler', '~> 2'
32
32
  spec.add_development_dependency 'rake', '~> 13'
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.0.6
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - FloXcoder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-25 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -84,30 +84,30 @@ dependencies:
84
84
  name: selenium-webdriver
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webdrivers
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '4'
103
+ version: '3'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '4'
110
+ version: '3'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: bundler
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -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.17
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