Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/Runtime/RowState/InCache.pm view on Meta::CPAN
package Alzabo::Runtime::RowState::InCache;
use strict;
use base qw(Alzabo::Runtime::RowState::Live);
BEGIN
{
no strict 'refs';
foreach my $meth ( qw( select select_hash ) )
{
my $super = "SUPER::$meth";
*{__PACKAGE__ . "::$meth"} =
sub { my $s = shift;
$s->refresh(@_) unless $s->_in_cache(@_);
$s->$super(@_);
};
}
}
sub update
{
my $class = shift;
my $row = shift;
my $old_id = $row->id_as_string;
$class->refresh($row) unless $class->_in_cache($row);
my $changed = $class->SUPER::update( $row, @_ );
return $changed if exists $row->{id_string};
Alzabo::Runtime::UniqueRowCache->delete_from_cache( $row->table->name, $old_id );
Alzabo::Runtime::UniqueRowCache->write_to_cache($row);
return $changed;
}
sub delete
{
my $class = shift;
my $row = shift;
my $old_id = $row->id_as_string;
$class->SUPER::delete( $row, @_ );
Alzabo::Runtime::UniqueRowCache->delete_from_cache( $row->table->name, $old_id );
}
sub refresh
{
my $class = shift;
$class->SUPER::refresh(@_);
# return if $class->_in_cache($row); #????
}
sub _in_cache
{
return
Alzabo::Runtime::UniqueRowCache->row_in_cache
( $_[1]->table->name, $_[1]->id_as_string );
}
( run in 0.569 second using v1.01-cache-2.11-cpan-39bf76dae61 )