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
- 
  
    
      #local_cache_key  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    :nodoc:. 
- 
  
    
      #name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    :nodoc:. 
Instance Method Summary collapse
- #call(env) ⇒ Object
- 
  
    
      #initialize(name, local_cache_key)  ⇒ Middleware 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Middleware. 
- #new(app) ⇒ Object
Constructor Details
#initialize(name, local_cache_key) ⇒ Middleware
Returns a new instance of Middleware.
| 16 17 18 19 20 | # File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 16 def initialize(name, local_cache_key) @name = name @local_cache_key = local_cache_key @app = nil end | 
Instance Attribute Details
#local_cache_key ⇒ Object (readonly)
:nodoc:
| 14 15 16 | # File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 14 def local_cache_key @local_cache_key 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
| 27 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 27 def call(env) LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new) response = @app.call(env) response[2] = ::Rack::BodyProxy.new(response[2]) do LocalCacheRegistry.set_cache_for(local_cache_key, nil) end cleanup_on_body_close = true response rescue Rack::Utils::InvalidParameterError [400, {}, []] ensure LocalCacheRegistry.set_cache_for(local_cache_key, nil) unless cleanup_on_body_close end | 
#new(app) ⇒ Object
| 22 23 24 25 | # File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 22 def new(app) @app = app self end |