Re: Object caching

javier ramirez
Fri, 17 Aug 2007 22:13:53 -0000

Hi,
> model, you can use find()''s :include to fetch it in one sql call.
> http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000992
>
>
>> Does Rails cache all objects that are accessed during a request
Also... ActiveRecord will keep a pretty simple (but somehow effective)
cache on a per-model basis. The last query result for each model is
cached, and if you are trying to execute the same query, then it will be
coming directly from memory. Take into account there is only a cached
resultset per model.

You can play a bit with that to see how it works by opening a console in
development mode and executing some finds as you are tailing the log.
You''ll see when you repeat the same find against a model, no new query
is launched againts the db.

If I''m not mistaken, rails 2 will improve the AR cache, but so far
that''s the way it works.

regards,

javier ramirez