How do you disable AR query cache globally?

Ref my earlier post in this group regarding a problem with AR query caching with MS SQL Server, I now find that the most convenient solution would be simply disabling query caching globally for this app.

Question is, how do you do that?

mh wrote:

Ref my earlier post in this group regarding a problem with AR query caching with MS SQL Server, I now find that the most convenient solution would be simply disabling query caching globally for this app.

Question is, how do you do that?

all "global" settings should be in config/environment.rb or at least loaded from there.. while you are in that file, check out the comments for a whole host of features that you can turn on and off (including caching I believe)

hth

ilan

Ilan,

Thanks for your reply. Indeed, that's exactly what one would expect: to be able to set something in environment.rb (or in an environment- specific file) such as:

config.active_record.query_cache_enabled = false

(That particular code fails with undefined method `query_cache_enabled=' for ActiveRecord::Base:Class.)

When you peruse the code that does the query results caching, you might think you could setup an initializer that does the following:

ActiveRecord::Base.connection.query_cache_enabled = false

Unfortunately, that also doesn't work, because ActiveController actually explicitly enables the query cache when calling an action in action_controller/caching.rb:

module ActionController #:nodoc:   # ...   # Note: To turn off all caching and sweeping, set Base.perform_caching = false.   module Caching     def self.included(base) #:nodoc:       base.class_eval do         include Pages, Actions, Fragments

        if defined? ActiveRecord           include Sweeping, SqlCache         end

        @@perform_caching = true         cattr_accessor :perform_caching       end     end ...

Where SqlCache looks like:

    module SqlCache       def self.included(base) #:nodoc:         if defined?(ActiveRecord) && ActiveRecord::Base.respond_to? (:cache)           base.alias_method_chain :perform_action, :caching         end       end

      def perform_action_with_caching         ActiveRecord::Base.cache do           perform_action_without_caching         end       end     end

It's the ActiveRecord::Base.cache call that explicitly turns on query caching that was the remaining culprit for me.

Consequently, given no apparent alternative other than to turn off ALL caching using ActionController::Base.perform_caching = false, I have disincluded SqlCache from being included in my controller, and that has effectively disabled query caching. It appears there is no convenient way to selectively disable just query caching while maintaining the other sorts of caching that Rails does for you. If someone else has a Better Way (tm), please advise.

Michael

It's the ActiveRecord::Base.cache call that explicitly turns on query caching that was the remaining culprit for me.

Michael

On Mar 17, 7:31�pm, Ilan Berci <rails-mailing-l...@andreas-s.net>

Michael, Would it be possible to open up the ActiveRecord::Base and alias_method_chain the query caching methods to return nil or empty sets which will effectively "disable it"?

I usually do my monkey patching in /lib and then load them up in config/environment.rb..

Thanks for taking the time to explain it fully to me.. was a very interesting read..

good luck and keep me informed..

ilan