Class: ActiveSupport::Cache::Strategy::LocalCache::Middleware

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name, local_cache_key) ⇒ Middleware

Returns a new instance of Middleware.


15
16
17
18
19
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 15

def initialize(name, local_cache_key)
  @name             = name
  @local_cache_key = local_cache_key
  @app              = nil
end

Instance Attribute Details

#local_cache_keyObject (readonly)

Returns the value of attribute local_cache_key


13
14
15
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 13

def local_cache_key
  @local_cache_key
end

#nameObject (readonly)

Returns the value of attribute name


13
14
15
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 13

def name
  @name
end

Instance Method Details

#call(env) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 26

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
  response
rescue Rack::Utils::InvalidParameterError
  LocalCacheRegistry.set_cache_for(local_cache_key, nil)
  [400, {}, []]
rescue Exception
  LocalCacheRegistry.set_cache_for(local_cache_key, nil)
  raise
end

#new(app) ⇒ Object


21
22
23
24
# File 'activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb', line 21

def new(app)
  @app = app
  self
end