As most of you know, Rails 3.1 introduces query caching for
ActiveRecord. Great change all-in-all, but for those of us with IT
department mandates for using MySQL (yeah, yeah, I know...), it's kind
of a mixed bag.
I need to disable query caching in a project I'm building based on
3.1. I've tried a couple different approaches, both without any
success. I was hoping some one could enlighten me on how to do that,
The first approach I tried was to create an initializer (config/
initializer/active_record.rb) and include this code:
(Documented at http://edgeapi.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/QueryCache.html
without comments or examples, unsurprisingly).
This doesn't appear to work as I'm still seeing prepared statement
caching going on in my log file:
Started GET "/dashboard" for 127.0.0.1 at 2011-08-06 22:43:07 -0600
Processing by DashboardController#index as HTML
User Load (13.4ms) SELECT "users".* FROM "users" WHERE "users"."id"
= $1 LIMIT 1 [["id", 1]]
Rendered dashboard/index.html.erb within layouts/application (0.3ms)
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1
So my next attempt was to place it in config/environments/
development.rb (I'm of course trying to get this to work in
development mode before doing it in production, obviously):
# ... other stuff ...
Same deal. I tried also changing that to
config.active_record.cache_queries = false - no such luck (and that
was just a long shot guess).
Can anyone explain to me exactly how I'm supposed to turn this off?