views:

12

answers:

1

In the process of looking at my logs from Mongrel, I found some SQL statements that I wanted to optimize. While looking into these, I noticed that these entries sometimes have CACHE in front of them, e.g.:

CACHE (0.0ms)   SELECT * FROM `customers` WHERE (`customers`.`id` = 35) 

Given the execution time, I'm assuming Mongrel really is caching this data. My question is how is this configured? I haven't been able to find much online about caching of model data; most of what I've read has to do with caching static pages or page fragments. I haven't done anything explicitly to enable this caching, so I'm really just looking for a pointer on how it's configured and how it works. Thanks in advance!

+1  A: 

It isn't actually anything to do with mongrel. Rails does a ActiveRecord::Base.cache around every controller action by default. This means that in the scope of that action it will cache the results of queries and provide the results from the cache rather than hitting the database again. You should see an identical query higher in the log (within the same action) that is not prefixed with CACHE which is the original query for which the results have been stored.

Some more details here.

Shadwell
This is exactly what I was looking for. Thanks!
Chris Hart