Class: WurflCloud::Rack::CacheManager

Inherits:
Object
  • Object
show all
Defined in:
lib/wurfl_cloud/rack/cache_manager.rb

Constant Summary collapse

'WurflCloud_Client'
EXPIRY =
86400

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ CacheManager

Returns a new instance of CacheManager.



18
19
20
# File 'lib/wurfl_cloud/rack/cache_manager.rb', line 18

def initialize(app, options={})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wurfl_cloud/rack/cache_manager.rb', line 21

def call(env)
  # extract cookie
  request = Rack::Request.new(env)
  env['wurfl.cookie.device_cache'] = extract_wurfl_cookie(request.cookies)
  
  # execute upstream request
  status, headers, body = @app.call(env)
  
  # store cookie
  response = Rack::Response.new body, status, headers
  response.set_cookie(COOKIE_NAME, {:value => {'date_set'=>Time.now.to_i, 'capabilities'=>env['wurfl.cookie.device_cache']}.to_json, :path => "/", :expires => Time.now+EXPIRY})
  response.finish 
end