BUGFIX: mobile ui was being cached for anon views

This commit is contained in:
Sam
2014-01-09 14:08:42 +11:00
parent e8afe87412
commit 177983afe6
4 changed files with 39 additions and 10 deletions

View File

@@ -1,3 +1,5 @@
require_dependency "mobile_detection"
module Middleware
class AnonymousCache
@@ -10,8 +12,19 @@ module Middleware
@env = env
end
def is_mobile?
@is_mobile ||=
begin
session = @env["rack.session"]
params = ActionDispatch::Request.new(@env).params
user_agent = @env["HTTP_USER_AGENT"]
MobileDetection.resolve_mobile_view!(user_agent,params,session) ? :true : :false
end == :true
end
def cache_key
@cache_key ||= "ANON_CACHE_#{@env["HTTP_HOST"]}#{@env["REQUEST_URI"]}"
@cache_key ||= "ANON_CACHE_#{@env["HTTP_HOST"]}#{@env["REQUEST_URI"]}|m=#{is_mobile?}"
end
def cache_key_body