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.



11
12
13
# File 'lib/wurfl_cloud/rack/cache_manager.rb', line 11

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

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wurfl_cloud/rack/cache_manager.rb', line 14

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