seo_cache 1.0.5 → 1.1.1

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: 36c446ef0dc5b6781157d81939f519c60e024ef6b4b0a9709b23f71cf2a96684
4
- data.tar.gz: 73f5a4fe10538b1292e8482d82f7411da4380ded38bcb13ba3b1565a3267576e
3
+ metadata.gz: 959dca2a3a9df2edb1bf3b7ff01e09a5632fb572624d101acc46a2a773f1de4f
4
+ data.tar.gz: 176b714c37870807890538accd50b47849c42702e734fb0124841dc6df870296
5
5
  SHA512:
6
- metadata.gz: 7e4f9582ca1e55fabd778adedec0cef4f715ea8fa78e3be1fc85a3982f2e4c8a48dfa8954154208735d5a7daf02c7f8da682c8b5f96d008bf5f8a829706d2f77
7
- data.tar.gz: 2c6c965ec2cb3621f10e91f8cc75bad2d032825dfebe629cf0a023a74382b3676550f9060c68deb110b21429381e5e4127938c2b5aa2da839925436e7ec32ccc
6
+ metadata.gz: 433a9a7f97517d4c8e2b1335997c0d7de7c41044a51f8c90e3439ea07e92b4174986233e3ead7a72dd7a117674fc3b2d2cce2eab162776867e4afe5b8dafe3b6
7
+ data.tar.gz: 93e2d478189c54928bd6adeaa48aca393b96f1a5b5807bd44019880a9808d78e97e633fcdfe4a13bf5379faccbbfa373491a4f372607637e4de2468edb250594
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 1.1.1
2
+
3
+ - Add new option to use locale as first directory for cache path
4
+
5
+ ## 1.1.0
6
+
7
+ - Update dependencies
8
+
9
+ ## 1.0.7
10
+
11
+ - Use new syntax to check if Redis key exists
12
+
13
+ ## 1.0.6
14
+
15
+ - Logs only missed cache for success response
16
+
1
17
  ## 1.0.5
2
18
 
3
19
  - Use correct path for index page with multiple domain names
@@ -36,9 +36,15 @@ module SeoCache
36
36
  else
37
37
  Thread.new do
38
38
  prerender_data = page_render(env)
39
- # Extract status from render page or return 404
40
- status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first
41
- after_render(env, prerender_data, status || 200)
39
+ # Extract status from render page or return success (200)
40
+ status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first || 200
41
+
42
+ if SeoCache.log_missed_cache && status.to_s.start_with?('2')
43
+ env_request = Rack::Request.new(env)
44
+ SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})")
45
+ end
46
+
47
+ after_render(env, prerender_data, status)
42
48
  end
43
49
  end
44
50
  elsif prerender_params?(env)
@@ -94,7 +100,7 @@ module SeoCache
94
100
  return false if SeoCache.blacklist_params.present? && SeoCache.blacklist_params.any? { |param| query_params.has_key?(param) }
95
101
 
96
102
  # if it is a bot and is requesting a resource...don't prerender
97
- return false if @extensions_to_ignore.any? { |extension| request.fullpath.include? extension }
103
+ return false if @extensions_to_ignore.any? { |extension| request.fullpath.include?(extension) }
98
104
 
99
105
  # if it is a bot and not requesting a resource and is not whitelisted...don't prerender
100
106
  return false if SeoCache.whitelist_urls.present? && SeoCache.whitelist_urls.all? { |whitelisted| !Regexp.new(whitelisted).match(request.fullpath) }
@@ -180,7 +186,9 @@ module SeoCache
180
186
  # return nil unless @options[:before_render]
181
187
  # cached_render = @options[:before_render].call(env)
182
188
 
183
- 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))
184
192
 
185
193
  return nil unless cached_render
186
194
 
@@ -207,12 +215,21 @@ module SeoCache
207
215
  def after_render(env, response, status = 200)
208
216
  return unless response && SeoCache.cache_only_status.include?(status.to_i)
209
217
 
218
+ env_request = Rack::Request.new(env)
219
+
210
220
  if SeoCache.log_missed_cache
211
- env_request = Rack::Request.new(env)
212
221
  SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})")
213
222
  end
214
223
 
215
- @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
216
233
  end
217
234
  end
218
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, nil, 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.5'.freeze
2
+ VERSION = '1.1.1'.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.5
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-05-23 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