Class: ActiveSupport::Cache::Strategy::LocalCache::Middleware
- Defined in:
- activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb
Overview
– This class wraps up local storage for middlewares. Only the middleware method should construct them.
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#name ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(name, cache) ⇒ Middleware
constructor
A new instance of Middleware.
- #new(app) ⇒ Object
Constructor Details
#initialize(name, cache) ⇒ Middleware
Returns a new instance of Middleware.
17 18 19 20 21 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 17 def initialize(name, cache) @name = name @cache = cache @app = nil end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
15 16 17 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 15 def cache @cache end |
#name ⇒ Object (readonly)
:nodoc:
14 15 16 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 14 def name @name end |
Instance Method Details
#call(env) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 28 def call(env) cache.new_local_cache response = @app.call(env) response[2] = ::Rack::BodyProxy.new(response[2]) do cache.unset_local_cache end cleanup_on_body_close = true response rescue Rack::Utils::InvalidParameterError [400, {}, []] ensure cache.unset_local_cache unless cleanup_on_body_close end |
#new(app) ⇒ Object
23 24 25 26 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 23 def new(app) @app = app self end |