Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Data/ObjectDriver/Driver/Cache/RAM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sub add_to_cache {
my $driver = shift;

$driver->start_query('RAMCACHE_ADD ?', \@_);
my $ret = $Cache{$_[0]} = $_[1];
my $ret = $Cache{$_[0]} = $_[1]->clone;
$driver->end_query(undef);

return if !defined $ret;
Expand All @@ -41,7 +41,7 @@ sub update_cache {
my $driver = shift;

$driver->start_query('RAMCACHE_SET ?', \@_);
my $ret = $Cache{$_[0]} = $_[1];
my $ret = $Cache{$_[0]} = $_[1]->clone;
$driver->end_query(undef);

return if !defined $ret;
Expand Down
14 changes: 13 additions & 1 deletion t/31-cached.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BEGIN {
plan skip_all => 'Tests require Cache::Memory';
}
}
plan tests => 105;
plan tests => 106;

setup_dbs({
global => [ qw( recipes ingredients ) ],
Expand Down Expand Up @@ -185,6 +185,18 @@ ok(! Ingredient->lookup(1), "really deleted");
is($recipe->remove, 1, 'Recipe removed successfully');
is($recipe2->remove, 1, 'Recipe removed successfully');

# make sure cache is not changed before save
{
my $r = Recipe->new;
$r->title('to replace');
$r->insert;
my $id = $r->recipe_id;
my $r1 = Recipe->lookup($id);
$r1->title('replaced');
my $r2 = Recipe->lookup($id);
is $r2->title, 'to replace', 'not replaced yet';
}

require './t/txn-common.pl';

END {
Expand Down
9 changes: 6 additions & 3 deletions t/lib/cached/Recipe.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ use base qw( Data::ObjectDriver::BaseObject );
use DodTestUtil;

use Data::ObjectDriver::Driver::DBI;
use Data::ObjectDriver::Driver::Cache::RAM;

__PACKAGE__->install_properties({
columns => [ 'recipe_id', 'title' ],
datasource => 'recipes',
primary_key => 'recipe_id',
driver => Data::ObjectDriver::Driver::DBI->new(
dsn => DodTestUtil::dsn('global'),
reuse_dbh => 1,
driver => Data::ObjectDriver::Driver::Cache::RAM->new(
fallback => Data::ObjectDriver::Driver::DBI->new(
dsn => DodTestUtil::dsn('global'),
reuse_dbh => 1,
),
),
});

Expand Down