class Racknga::Middleware::PerUserAgentCache
This is a helper middleware for Racknga::Middleware::Cache
.
If your Rack application provides different views to mobile user agent and PC user agent in the same URL, this middleware is useful. Your Rack application can has different caches for mobile user agent and PC user agent.
This middleware requires jpmobile.
Usage:
use Racnkga::Middleware::PerUserAgentCache use Racnkga::Middleware::Cache, :database_path => "var/cache/db" run YourApplication
@see jpmobile-rails.org/ jpmobile @see Racknga::Middleware::Cache
Public Class Methods
new(application)
click to toggle source
# File lib/racknga/middleware/cache.rb, line 43 def initialize(application) @application = application end
Public Instance Methods
call(environment)
click to toggle source
For Rack.
# File lib/racknga/middleware/cache.rb, line 48 def call(environment) mobile = environment["rack.jpmobile"] if mobile last_component = mobile.class.name.split(/::/).last user_agent_key = "mobile:#{last_component.downcase}" else user_agent_key = "pc" end key = environment[Cache::KEY] environment[Cache::KEY] = [key, user_agent_key].join(":") @application.call(environment) end