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

Inherits:
Object
  • Object
show all
Defined in:
activesupport/lib/active_support/cache/strategy/local_cache.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


70
71
72
73
74
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 70

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


68
69
70
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 68

def local_cache_key
  @local_cache_key
end

#nameObject (readonly)

Returns the value of attribute name


68
69
70
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 68

def name
  @name
end

Instance Method Details

#call(env) ⇒ Object


81
82
83
84
85
86
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 81

def call(env)
  LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new)
  @app.call(env)
ensure
  LocalCacheRegistry.set_cache_for(local_cache_key, nil)
end

#new(app) ⇒ Object


76
77
78
79
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 76

def new(app)
  @app = app
  self
end