diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-02 14:04:41 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-02 14:05:06 -0800 |
commit | b247c8d71a54d684a1c307986a03d1759bbc20e0 (patch) | |
tree | 33ea16105c99d47ebd2db1b7176be5671f88c0d9 /activesupport/lib/active_support/cache | |
parent | b7cf1f4ccfaac3b50c09df484062fdc92b340876 (diff) | |
download | rails-b247c8d71a54d684a1c307986a03d1759bbc20e0.tar.gz rails-b247c8d71a54d684a1c307986a03d1759bbc20e0.tar.bz2 rails-b247c8d71a54d684a1c307986a03d1759bbc20e0.zip |
* LocalCache strategy is now a real middleware class, not an anonymous class
posing for pictures.
Diffstat (limited to 'activesupport/lib/active_support/cache')
-rw-r--r-- | activesupport/lib/active_support/cache/strategy/local_cache.rb | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 4dce35f1c9..99b26b19fe 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -50,34 +50,40 @@ module ActiveSupport end end - # Middleware class can be inserted as a Rack handler to be local cache for the - # duration of request. - def middleware - @middleware ||= begin - klass = Class.new - klass.class_eval(<<-EOS, __FILE__, __LINE__ + 1) - class << self - def name - "ActiveSupport::Cache::Strategy::LocalCache" - end - alias :to_s :name - end + #-- + # This class wraps up local storage for middlewares. Only the middleware method should + # construct them. + class Middleware # :nodoc: + attr_reader :name, :thread_local_key + alias :to_s :name - def initialize(app) - @app = app - end + def initialize(name, thread_local_key) + @name = name + @thread_local_key = thread_local_key + @app = nil + end - def call(env) - Thread.current[:#{thread_local_key}] = LocalStore.new - @app.call(env) - ensure - Thread.current[:#{thread_local_key}] = nil - end - EOS - klass + def new(app) + @app = app + self + end + + def call(env) + Thread.current[thread_local_key] = LocalStore.new + @app.call(env) + ensure + Thread.current[thread_local_key] = nil end end + # Middleware class can be inserted as a Rack handler to be local cache for the + # duration of request. + def middleware + @middleware ||= Middleware.new( + "ActiveSupport::Cache::Strategy::LocalCache", + thread_local_key) + end + def clear(options = nil) # :nodoc: local_cache.clear(options) if local_cache super |