Re: possible improvement of Live_Objects cache
[prev]
[thread]
[next]
[Date index for 2005/07/01]
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.
> #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).
> 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? 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.
- Perrin
|
|
Re: possible improvement of Live_Objects cache
Perrin Harkins 04:28 on 01 Jul 2005
|