seo_cache 1.0.3 → 1.0.7

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: f2c6084cfed22c86d8dae948445d042fb5bcccd8a01afac54974dfaa96181f20
4
- data.tar.gz: a71c76d0d492bb9058d68a81ae8c5aa3170ef09d64192818d6f3a573453f18c9
3
+ metadata.gz: 91e81cc42e58735dd234bd336c165f5f98c910be1352d411328773ec665bafc3
4
+ data.tar.gz: 4eb8d5a45fb09013a626ad2dd1fba85dae74d93a7db47756b6761d1c1a6abc09
5
5
  SHA512:
6
- metadata.gz: 454155f0bcc296c6ccd1d7d3eafa90d5a83f17a38c1d24cdd4d52a7ae44eb2dca7dc493fad4233c30b33fb6183028a39bb7e8c60baa55a61533b22ac239267fd
7
- data.tar.gz: cf60d5d45b01fc2de32ee0963bd086e48859adcc6abcfee8921dcade7a38bdaae09727dfa025a49c0116f36fcff76f6adb651000293f6514db13d2415ccb223c
6
+ metadata.gz: a40d821a8bdeb984d5a0f52840680e76d7867bc5044805ccebe719ee485d79f9df16a98c1307704b9e869844f06e159bf96528293c4ca4383fa1fb60299970ae
7
+ data.tar.gz: 6bd0c086023df029305d247d48f4a0a08a0af23d85c739cce351134f21ca7e4c225f5f3ea5c4b4cad42f805ae70929f0d2984106499fa3ceb9e34d7ba4963ac0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 1.0.7
2
+
3
+ - Use new syntax to check if Redis key exists
4
+
5
+ ## 1.0.6
6
+
7
+ - Logs only missed cache for success response
8
+
9
+ ## 1.0.5
10
+
11
+ - Use correct path for index page with multiple domain names
12
+
13
+ ## 1.0.4
14
+
15
+ - Add option to populate seo cache for multi-domains
16
+
1
17
  ## 1.0.3
2
18
 
3
19
  - Ensure page rendered status is present after head element
data/README.md CHANGED
@@ -227,6 +227,8 @@ end
227
227
 
228
228
  You can add the `force_cache: true` option to `SeoCache::PopulateCache` for overwrite cached data.
229
229
 
230
+ If your website has several domains (.com, .fr, ...), you need to generate your urls for each locale (each key is the locale). And use the `with_locale_keys: true` option.
231
+
230
232
  If you want to execute only through a rake task, you can comment the line which include the middleware. keep all options configured and remove only the middleware. Thus all pages will be cached and SeoCache isn't called for pages not in cache.
231
233
  It's useful if you have a script which generates all website pages (based on sitemap for instance) and you run script every day.
232
234
 
@@ -275,6 +277,8 @@ location / {
275
277
  rewrite ^/(.*)/$ /$1 last;
276
278
 
277
279
  try_files /seo_cache/$uri/index$cache_extension /seo_cache/$uri$cache_extension /seo_cache/$uri $uri @rubyproxy;
280
+ # Or for multi-domains:
281
+ # try_files /seo_cache/fr/$uri/index$cache_extension /seo_cache/fr/$uri$cache_extension /seo_cache/fr/$uri $uri @rubyproxy;
278
282
  }
279
283
 
280
284
  location @rubyproxy {
@@ -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) }
@@ -17,12 +17,12 @@ module SeoCache
17
17
  @redis.get(cache_path(path, extension)) if SeoCache.memory_cache? && @redis
18
18
  end
19
19
 
20
- def cache(content, path, extension = nil, gzip = Zlib::BEST_COMPRESSION)
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))
23
+ write_to_memory(content, cache_path(path, extension, locale_domain))
24
24
  else
25
- write_to_disk(content, cache_path(path, extension), gzip)
25
+ write_to_disk(content, cache_path(path, extension, locale_domain), gzip)
26
26
  end
27
27
  end
28
28
  end
@@ -35,7 +35,7 @@ module SeoCache
35
35
 
36
36
  def cache_exists?(path)
37
37
  if SeoCache.memory_cache? && @redis
38
- @redis.exists(cache_path(path))
38
+ @redis.exists?(cache_path(path))
39
39
  else
40
40
  File.exist?(cache_path(path))
41
41
  end
@@ -51,22 +51,22 @@ module SeoCache
51
51
  SeoCache.cache_extension
52
52
  end
53
53
 
54
- def cache_file(path, extension)
54
+ def cache_file(path, extension, locale_domain)
55
55
  name = if path.empty? || path =~ %r{\A/+\z}
56
56
  '/index'
57
57
  else
58
58
  URI::Parser.new.unescape(path.chomp('/'))
59
59
  end
60
60
 
61
- if File.extname(name).empty?
62
- name + (extension || default_extension)
63
- else
64
- name
65
- end
61
+ name = "#{locale_domain}/#{name}" if locale_domain
62
+
63
+ name += extension || default_extension if File.extname(name).empty?
64
+
65
+ name
66
66
  end
67
67
 
68
- def cache_path(path, extension = nil)
69
- File.join(cache_directory, cache_file(path, extension))
68
+ def cache_path(path, extension = nil, locale_domain = nil)
69
+ File.join(cache_directory, cache_file(path, extension, locale_domain))
70
70
  end
71
71
 
72
72
  def write_to_memory(content, path)
@@ -11,23 +11,40 @@ module SeoCache
11
11
  @page_render = PageRender.new
12
12
  @page_caching = PageCaching.new
13
13
 
14
- @force_cache = options.fetch(:force_cache, false)
14
+ @force_cache = options.fetch(:force_cache, false)
15
+ @with_locale_keys = options.fetch(:with_locale_keys, false)
15
16
  end
16
17
 
17
18
  def perform
18
- @paths.each do |path|
19
- next if @page_caching.cache_exists?(path) && !@force_cache
20
-
21
- url = @host + path
22
- url += path.include?('?') ? '&' : '?'
23
- url += "#{SeoCache.prerender_url_param}=true"
24
-
25
- page_source = @page_render.get(url, false)
26
- @page_caching.cache(page_source, path) if page_source
19
+ if @with_locale_keys
20
+ @paths.each do |locale, paths|
21
+ paths.each do |path|
22
+ generate_cache(path, locale)
23
+ end
24
+ end
25
+ else
26
+ @paths.each do |path|
27
+ generate_cache(path)
28
+ end
27
29
  end
28
30
 
29
31
  ensure
30
32
  @page_render.close_connection
31
33
  end
34
+
35
+ private
36
+
37
+ def generate_cache(path, locale_domain = nil)
38
+ return if @page_caching.cache_exists?(path) && !@force_cache
39
+
40
+ url = @host + path
41
+ url += path.include?('?') ? '&' : '?'
42
+ url += "#{SeoCache.prerender_url_param}=true"
43
+
44
+ page_source = @page_render.get(url, false)
45
+ return unless page_source
46
+
47
+ @page_caching.cache(page_source, path, locale_domain)
48
+ end
32
49
  end
33
50
  end
@@ -1,3 +1,3 @@
1
1
  module SeoCache
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.0.7'.freeze
3
3
  end
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.3
4
+ version: 1.0.7
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-01 00:00:00.000000000 Z
11
+ date: 2021-09-19 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.16
232
+ rubygems_version: 3.2.27
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: Cache dedicated for SEO with Javascript rendering