aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-02 14:04:41 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-02 14:05:06 -0800
commitb247c8d71a54d684a1c307986a03d1759bbc20e0 (patch)
tree33ea16105c99d47ebd2db1b7176be5671f88c0d9 /activesupport
parentb7cf1f4ccfaac3b50c09df484062fdc92b340876 (diff)
downloadrails-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')
-rw-r--r--activesupport/CHANGELOG3
-rw-r--r--activesupport/lib/active_support/cache/strategy/local_cache.rb52
2 files changed, 32 insertions, 23 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 99cea2586b..373236ce9a 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,8 @@
*Rails 3.1.0 (unreleased)*
+* LocalCache strategy is now a real middleware class, not an anonymous class
+posing for pictures.
+
* ActiveSupport::Dependencies::ClassCache class has been introduced for
holding references to reloadable classes.
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