lib/seo_cache/middleware.rb in seo_cache-1.0.1 vs lib/seo_cache/middleware.rb in seo_cache-1.0.2

- old
+ new

@@ -20,11 +20,11 @@ cached_response = before_render(env) return cached_response.finish if cached_response.present? if SeoCache.log_missed_cache - env_request = Rack::Request.new(env) + env_request = Rack::Request.new(env) SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})") end if SeoCache.prerender_service_url.present? prerender_response = prerender_service(env) @@ -34,12 +34,12 @@ return response.finish end else Thread.new do prerender_data = page_render(env) - # Extract status from render page (return 500 if status cannot be found, some problems happen somewhere) - status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first || 500 + # Extract status from render page or return 404 + status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first || 404 after_render(env, prerender_data, status || 200) end end elsif prerender_params?(env) env['seo_mode'] = true @@ -204,9 +204,14 @@ return PageRender.new.get(url) end def after_render(env, response, status = 200) return unless response && SeoCache.cache_only_status.include?(status.to_i) + + if SeoCache.log_missed_cache + env_request = Rack::Request.new(env) + SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})") + end @page_caching.cache(response, Rack::Request.new(env).path) end end end