Re: possible improvement of Live_Objects cache

[prev] [thread] [next] [Date index for 2005/07/11]

From: Jasper Cramwinckel
Subject: Re: possible improvement of Live_Objects cache
Date: 10:08 on 11 Jul 2005
Hi,

Thank you for taking the time to looking at this!

Perrin Harkins wrote:

>On Mon, 2005-06-27 at 12:44 +0200, Jasper Cramwinckel wrote:
>  
>
>>I have a question about object caching in Class::DBI using %Live_Objects
>>in Class::DBI->_init().
>>    
>>
>
>That isn't a cache.  If you want to cache, you have to do that yourself in a subclass.
>  
>
Hm, does that mean I can not persuade you guys to look in %Live_Objects 
during each retrieve() and skip the query when the object is available? ;-)

>>#Here, the cds with all essential fields are retrieved from the
>>#  db with some query, but the content is ignored for cds of
>>#  which an (empty) object already exists in %Live_Objects.
>>    
>>
>
>The goal is to prevent you from having two objects in memory that both
>represent the same row.  It isn't intended to reduce the number of SQL
>queries, although that isn't a bad idea if it can be done safely and
>without actually turning the object index into a cache (which you can do
>yourself in a subclass).
>  
>
Note that with the current implementation, %Live_Objects van actually 
cost extra queries because a retrieve with essential fields can be 
ignored when in (empty) object is already in %Live_Objects.

>>The following fix reduced the number of queries in my application a lot,
>>but I am not sure it works in all situations:
>>
>>< # don't store it unless all keys are present
>>< if ($obj_key && $Weaken_Is_Available) {
>>---
>>    
>>
>>># don't store it unless all keys are present
>>>if(defined($obj = $Live_Objects{$obj_key}) ) {
>>>    if( scalar keys %$obj == scalar @primary_columns ) {
>>>        $obj->_attribute_store(%$data);
>>>    }
>>>} else {
>>>      
>>>
>
>Could you send the diff in unified (-u) format? 
>
Sorry, here it is:

--- DBI.pm      Mon Jul 11 12:02:18 2005
+++ DBI2.pm     Mon Jul 11 12:02:03 2005
@@ -523,7 +523,13 @@
                        sort @primary_columns;
        }
 
-       unless (defined($obj = $Live_Objects{$obj_key})) {
+       if (defined($obj = $Live_Objects{$obj_key})) {
+
+               if( scalar keys %$obj == scalar @primary_columns ) {
+                       $obj->_attribute_store(%$data);
+               }
+
+       } else {
 
                # not in the object_index, or we don't have all keys yet
                $obj = bless {}, $class;

> I don't quite see how
>this fits.  I get the gist though -- if the in-memory object only has
>the primary keys defined, dump the existing data into it.  That's
>probably safe.  Doing this in situations where there is more than just
>the primary key would be questionable.
>  
>
Why?

Jasper

possible improvement of Live_Objects cache
Jasper Cramwinckel 10:44 on 27 Jun 2005

Re: possible improvement of Live_Objects cache
Perrin Harkins 04:28 on 01 Jul 2005

Re: possible improvement of Live_Objects cache
Jasper Cramwinckel 10:08 on 11 Jul 2005

Re: possible improvement of Live_Objects cache
Perrin Harkins 17:39 on 11 Jul 2005

Generated at 16:35 on 28 Jul 2005 by mariachi v0.52