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, thread_local_key) ⇒ Middleware

Returns a new instance of Middleware.



59
60
61
62
63
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 59

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



57
58
59
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 57

def name
  @name
end

#thread_local_keyObject (readonly)

Returns the value of attribute thread_local_key



57
58
59
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 57

def thread_local_key
  @thread_local_key
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  Thread.current[thread_local_key] = LocalStore.new
  @app.call(env)
ensure
  Thread.current[thread_local_key] = nil
end

#new(app) ⇒ Object



65
66
67
68
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 65

def new(app)
  @app = app
  self
end