1 package DBIx::Class::ObjectCache;
6 use base qw/Class::Data::Inheritable/;
8 __PACKAGE__->mk_classdata('cache');
12 $self->NEXT::ACTUAL::insert(@_);
13 $self->_insert_into_cache if $self->cache;
18 my ($self,@vals) = @_;
19 return $self->NEXT::ACTUAL::find(@vals) unless $self->cache;
21 # this is a terrible hack here. I know it can be improved.
22 # but, it's a start anyway. probably find in PK.pm needs to
23 # call a hook, or some such thing. -Dave/ningu
25 my @pk = keys %{$self->_primaries};
26 if (ref $vals[0] eq 'HASH') {
27 my $cond = $vals[0]->{'-and'};
28 $key = $self->_create_ID(%{$cond->[0]}) if ref $cond eq 'ARRAY';
29 } elsif (@pk == @vals) {
32 $key = $self->_create_ID(%data);
34 $key = $self->_create_ID(@vals);
36 if ($key and $object = $self->cache->get($key)) {
40 $object = $self->NEXT::ACTUAL::find(@vals);
41 $object->_insert_into_cache if $object;
47 $self->cache->remove($self->ID) if $self->cache;
48 return $self->NEXT::ACTUAL::update(@_);
53 $self->cache->remove($self->ID) if $self->cache;
54 return $self->NEXT::ACTUAL::delete(@_);
57 sub _insert_into_cache {
59 if (my $key = $self->ID) {
60 if (my $object = $self->new( $self->{_column_data} )) {
61 $self->cache->set($key,$object);