cbernaut
cbernaut

Reputation: 41

Why is rails query caching not working?

In my development environment I have a single request that is generating hundreds of the same queries:

Person Load (24.4ms)  SELECT "persons".* FROM "persons" WHERE ("persons"."person_id" = 517) LIMIT 1  
. . .   
Person Load (64.4ms)  SELECT "persons".* FROM "persons" WHERE ("persons"."person_id" = 517) LIMIT 1

Why is this? I thought Rails was supposed to enable Query caching by default on a per request basis?

config/development.rb:  
config.cache_classes = false  
config.perform_caching = true    
. . .    
# Show full error reports and disable caching  
config.consider_all_requests_local       = true  
config.action_view.debug_rjs             = true  
config.action_controller.perform_caching = true  
config.active_support.deprecation        = :log  

Upvotes: 4

Views: 1405

Answers (2)

njorden
njorden

Reputation: 2606

If you're connecting to multiple databases (say by using establish_connection in certain models), it appears that only the ActiveRecord::Base.connection gets query caching enabled. Not sure if that's the case here, but certainly a tricky side effect of connecting to multiple DBs.

Upvotes: 5

jwilkins
jwilkins

Reputation: 401

Are you using passenger and memcache in production?

http://www.russbrooks.com/2010/10/20/rails-cache-memcache-on-passenger-with-smart-spawning

Upvotes: 0

Related Questions