aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/query_cache.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-12-22 11:31:18 -0600
committerJoshua Peek <josh@joshpeek.com>2008-12-22 11:31:18 -0600
commitaa002c0e86afdc83693f14667a710107843f0fbd (patch)
tree0ec063c6a18b2f9f523ada8a5d338b68dd562be2 /activerecord/lib/active_record/query_cache.rb
parent63aac338332a06d3c9e28dde7954679703ec7620 (diff)
downloadrails-aa002c0e86afdc83693f14667a710107843f0fbd.tar.gz
rails-aa002c0e86afdc83693f14667a710107843f0fbd.tar.bz2
rails-aa002c0e86afdc83693f14667a710107843f0fbd.zip
ActiveRecord::QueryCache middleware
Diffstat (limited to 'activerecord/lib/active_record/query_cache.rb')
-rw-r--r--activerecord/lib/active_record/query_cache.rb38
1 files changed, 25 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb
index a8af89fcb9..eb92bc2545 100644
--- a/activerecord/lib/active_record/query_cache.rb
+++ b/activerecord/lib/active_record/query_cache.rb
@@ -1,20 +1,32 @@
module ActiveRecord
- module QueryCache
- # Enable the query cache within the block if Active Record is configured.
- def cache(&block)
- if ActiveRecord::Base.configurations.blank?
- yield
- else
- connection.cache(&block)
+ class QueryCache
+ module ClassMethods
+ # Enable the query cache within the block if Active Record is configured.
+ def cache(&block)
+ if ActiveRecord::Base.configurations.blank?
+ yield
+ else
+ connection.cache(&block)
+ end
end
+
+ # Disable the query cache within the block if Active Record is configured.
+ def uncached(&block)
+ if ActiveRecord::Base.configurations.blank?
+ yield
+ else
+ connection.uncached(&block)
+ end
+ end
+ end
+
+ def initialize(app)
+ @app = app
end
- # Disable the query cache within the block if Active Record is configured.
- def uncached(&block)
- if ActiveRecord::Base.configurations.blank?
- yield
- else
- connection.uncached(&block)
+ def call(env)
+ ActiveRecord::Base.cache do
+ @app.call(env)
end
end
end