Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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  
like image 246
cbernaut Avatar asked Sep 12 '25 05:09

cbernaut


1 Answers

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.

like image 75
njorden Avatar answered Sep 14 '25 18:09

njorden