It appears from a simple test that if I perform two queries (even the same query twice in a row) that return the same row from the database, I get two distinct copies of the same object. Is there a way to turn on some sort of identity-based caching with AR? Surely I''m missing something simple, but I can''t seem to find any documentation on this. Thanks! -d -- Posted via http://www.ruby-forum.com/.
Sorry to re-post...but does anyone have information on this? Dave Wood wrote:> It appears from a simple test that if I perform two queries (even the > same query twice in a row) that return the same row from the database, I > get two distinct copies of the same object. > > Is there a way to turn on some sort of identity-based caching with AR? > Surely I''m missing something simple, but I can''t seem to find any > documentation on this. > > Thanks! > -d-- Posted via http://www.ruby-forum.com/.
On 14/12/2005, at 4:09 AM, Dave Wood wrote:> It appears from a simple test that if I perform two queries (even the > same query twice in a row) that return the same row from the > database, I > get two distinct copies of the same object. > > Is there a way to turn on some sort of identity-based caching with AR? > Surely I''m missing something simple, but I can''t seem to find any > documentation on this.You are loading twice, so you get two objects. Rails doesn''t cache at all in development mode. I''m not sure about production mode, but this is expected behaviour in development mode. -- Phillip Hutchings phillip.hutchings-QrR4M9swfipWk0Htik3J/w@public.gmane.org
On 11/28/05, Dave Wood <dave-v2kKnsuhoL6GglJvpFV4uA@public.gmane.org> wrote:> It appears from a simple test that if I perform two queries (even the > same query twice in a row) that return the same row from the database, I > get two distinct copies of the same object.Yes, you''ll have two instances of the same object, but their =methods will return what you''d expect. Ensuring one instance is a lot harder than it seems at first glance, without introducing some kind of PersistenceSession ala hibernate''s Session. -- Cheers Koz
On 13-dec-2005, at 21:33, Michael Koziarski wrote:> On 11/28/05, Dave Wood <dave-v2kKnsuhoL6GglJvpFV4uA@public.gmane.org> wrote: >> It appears from a simple test that if I perform two queries (even the >> same query twice in a row) that return the same row from the >> database, I >> get two distinct copies of the same object. > > Yes, you''ll have two instances of the same object, but their => methods will return what you''d expect. Ensuring one instance is a lot > harder than it seems at first glance, without introducing some kind of > PersistenceSession ala hibernate''s Session.I''d also say it''s difficult with the way AR works right now (especially - the handling of joined attributes). Although I think it''s sort of _implied_ that you might be getting it for free if you already have ORM. But then again it would become a mapper. If you want identity caching take a look a cacheAR. http://rubyforge.org/projects/muravey-tools/ -- Julian ''Julik'' Tarkhanov me at julik.nl