[CDBI] Disable caching of column values?

Eric Busto EBusto at nvidia.com
Thu Jun 7 23:25:20 BST 2007


Whoops, last message sent prematurely!  :)

The previous post was:
http://osdir.com/ml/lang.perl.modules.class-dbi/2006-12/msg00021.html

I tweaked that slightly to override the Class::DBI get method:

package MyBaseClass;
use base 'Class::DBI';

sub get {
        my $self   = shift;
        my %pk     = map { $_ => 1 } $self->primary_columns;
        my @delete = grep { !$pk{$_} } @_;
        $self->_attribute_delete(@delete);
        return $self->SUPER::get(@_);
}

This seems to work fine.  Can anyone think of any potential problems
with this approach?

-----Original Message-----
From: Eric Busto 
Sent: Thursday, June 07, 2007 3:23 PM
To: 'Perrin Harkins'
Cc: classdbi at svr02.digitalcraftsmen.net
Subject: RE: [CDBI] Disable caching of column values?


I was hoping for a method that would not require additional code in the
application side.  However, you pointing out the need to call
_attribute_delete allowed me to fine tune my Google and code searching.
I came across the following post to the CDBI mailing list:


-----Original Message-----
From: pharkins at gmail.com [mailto:pharkins at gmail.com] On Behalf Of Perrin
Harkins
Sent: Thursday, June 07, 2007 2:52 PM
To: Eric Busto
Cc: classdbi at svr02.digitalcraftsmen.net
Subject: Re: [CDBI] Disable caching of column values?


On 6/7/07, Eric Busto <EBusto at nvidia.com> wrote:
> When the still-running application calls an accessor,
> I want it to have the latest data, instead of what is cached inside
the
> object.
>
> Can someone tell me how to disable the column value caching, so
> Class::DBI/the object will hit the database every time the accessor is
> called?

Create a new object every time.

my $foo = Foo->retrieve(17);
print $foo->bar;
undef $foo;
my $foo = Foo->retrieve(17); # fetched again
print $foo->bar; # current value

Alternatively, you can delete a single column so it will be fetched
again:

$foo->attribute_delete('bar');

That's a private method though and is probably different in different
releases.

- Perrin
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------



More information about the ClassDBI mailing list