Re: Object caching

William Pratt
Thu, 16 Aug 2007 13:57:15 -0000

You can pre-fetch the data in the controller. If it is an associated
model, you can use find()''s :include to fetch it in one sql call.
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000992

helzer wrote:
> Does Rails cache all objects that are accessed during a request?
>
> If one object is accessed several times during a request, would its
> value be read from memory, or fetched from the database over and over
> again?
>
> I''m sure that objects that were passed by the controller, like
> @something would be cached, because their reference is passed, but
> what about other objects which might be deleted by the garbage
> collection?
>
> So, if I plan to display the same object over and over again within a
> partial, for the same call, how do I make sure it''s not fetched
from
> the database on every render?
>
> Thanks,
> Amir
>
>
> >
>

--
Sincerely,

William Pratt

http://www.billpratt.net
billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org