Question about the Object Cache

[prev] [thread] [next] [Date index for 2005/04/21]

From: Ian McDonald-ONLINE
Subject: Question about the Object Cache
Date: 16:41 on 21 Apr 2005
Hi,

I had assumed that the Class::DBI object cache meant that if two
separate parts of my code tried to retrieve the same Class::DBI object
(for example by the primary index value), then they would get the same
object.

Then I put Carp::cluck statements after all the Class/DBI.pm execute
statements and found that the same ActiveClass->retrieve(217) statement
was being called multiple times from different contexts. After this, I
re-read the perldoc for Class::DBI, and found:
This is implemented using a simple object lookup index for all live
objects in memory. It is not a traditional cache - when your objects go
out of scope, they will be destroyed normally, and a future retrieve
will instantiate an entirely new object.
So what happens if the object is in memory, but not in scope? My code
takes this form, but makes mutliple calls to ActiveRecord->retrieve(id)
=2E.. and those multiple calls result in multiple calls to DBI->execute.
Is this the behavious you would expect? Or do I need to look more
closely at my code?

$x->{activeRecord} =3D retrieve ActiveRecord (id);

$x->{memberA} =3D retrieve MemberA ( id )
$x->{memberB} =3D retrieve MemberB ( id )

Sub MemberA::retrieve {
  my $class =3D shift;
   my $id =3D shift;
   my $self =3D { };
   bless $self, $class;
   $self->{activeRecord} =3D retrieve ActiveRecord (id);
   return $self;
}



--
Dr Ian McDonald
Software Engineer, Interactive Drama & Entertainment
A300, 56-58 Wood Lane (CH), London W12 7SB
020 822 56162
ian.mcdonald@xxx.xx.xx / "Ian McDonald-ONLINE" (not "Ian MacDonald")



http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless specifically
stated.
If you have received it in error, please delete it from your system.=20
Do not use, copy or disclose the information in any way nor act in
reliance on it and notify the sender immediately. Please note that the
BBC monitors e-mails sent or received.=20
Further communication will signify your consent to this.

Question about the Object Cache
Ian McDonald-ONLINE 16:41 on 21 Apr 2005

Re: Question about the Object Cache
Perrin Harkins 17:00 on 21 Apr 2005

Generated at 09:29 on 27 Apr 2005 by mariachi v0.52