lib/seo_cache/middleware.rb in seo_cache-1.1.0 vs lib/seo_cache/middleware.rb in seo_cache-1.1.1

- old
+ new

@@ -184,12 +184,14 @@ def before_render(env) # return nil unless @options[:before_render] # cached_render = @options[:before_render].call(env) - cached_render = @page_caching.get(Rack::Request.new(env).path) + env_request = Rack::Request.new(env) + cached_render = @page_caching.get(env_request.path, get_locale(env_request.params, env_request.host)) + return nil unless cached_render if cached_render.is_a?(String) Rack::Response.new(cached_render, 200, 'Content-Type' => 'text/html; charset=utf-8') elsif cached_render.is_a?(Rack::Response) @@ -211,14 +213,23 @@ end def after_render(env, response, status = 200) return unless response && SeoCache.cache_only_status.include?(status.to_i) + env_request = Rack::Request.new(env) + 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) + @page_caching.cache(response, env_request.path, get_locale(env_request.params, env_request.host)) + end + + def get_locale(params, host) + if SeoCache.locale_as_first_directory + SeoCache.locale_method ? SeoCache.locale_method.call(params, host) : I18n.locale + else + nil + end end end end