Permalink
Browse files

ActiveRecord::QueryCache middleware

  • Loading branch information...
1 parent 63aac33 commit aa002c0e86afdc83693f14667a710107843f0fbd @josh josh committed Dec 22, 2008
@@ -27,7 +27,6 @@ module Caching
autoload :Actions, 'action_controller/caching/actions'
autoload :Fragments, 'action_controller/caching/fragments'
autoload :Pages, 'action_controller/caching/pages'
- autoload :SqlCache, 'action_controller/caching/sql_cache'
autoload :Sweeping, 'action_controller/caching/sweeping'
def self.included(base) #:nodoc:
@@ -41,7 +40,7 @@ def self.cache_store=(store_option)
end
include Pages, Actions, Fragments
- include Sweeping, SqlCache if defined?(ActiveRecord)
+ include Sweeping if defined?(ActiveRecord)
@@perform_caching = true
cattr_accessor :perform_caching
@@ -1,18 +0,0 @@
-module ActionController #:nodoc:
- module Caching
- module SqlCache
- def self.included(base) #:nodoc:
- if defined?(ActiveRecord) && ActiveRecord::Base.respond_to?(:cache)
- base.alias_method_chain :perform_action, :caching
- end
- end
-
- protected
- def perform_action_with_caching
- ActiveRecord::Base.cache do
- perform_action_without_caching
- end
- end
- end
- end
-end
@@ -48,6 +48,7 @@ def to_prepare(identifier = nil, &block)
!ActionController::Base.allow_concurrency
}
middleware.use "ActionController::Failsafe"
+ middleware.use "ActiveRecord::QueryCache" if defined?(ActiveRecord)
["ActionController::Session::CookieStore",
"ActionController::Session::MemCacheStore",
@@ -3015,7 +3015,7 @@ def clone_attribute_value(reader_method, attribute_name)
end
Base.class_eval do
- extend QueryCache
+ extend QueryCache::ClassMethods
include Validations
include Locking::Optimistic, Locking::Pessimistic
include AttributeMethods
@@ -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

0 comments on commit aa002c0

Please sign in to comment.