possible improvement of Live_Objects cache

[prev] [thread] [next] [Date index for 2005/06/27]

From: Jasper Cramwinckel
Subject: possible improvement of Live_Objects cache
Date: 10:44 on 27 Jun 2005
Hi,

I have a question about object caching in Class::DBI using %Live_Objects
in Class::DBI->_init(). I came across a situation where it seems that
caching worked against me. That situation is as follows (where one CD
has many Tracks):

#Get some tracks (how the tracks are retrieved is not relevant).
#The Track objects will be stored in the cache with
#  all essential fields *and* the related CD objects will be
#  stored with only their id.
my @tracks = My::Tracks->find_some_tracks();

#Get some CDs
#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.
my @cds = My::CDs->find_some_cds();

#Even if CD.name is an essential column and the information has
#  just been retrieved in the previous statement, Class::DBI
#  will do a query for the essential columns of each cd of
#  which a track was retrieved in the first statement.
my @cd_names = map( $_->name, @cds );

Note that if order of the first two statements would have been reversed,
this problem would not have occurred. The example above is a bit
over-simplified, but you can imagine situations where some_cds() depends
on the result of find_some_tracks(), so the order cannot be reversed.

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 {

I am not very experienced in the Class::DBI internals. What do you
think? Would this always improve the performance of Class::DBI or are
there possible conflicts?

Thanks, 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