Author: timbo
Date: Fri Sep 28 09:39:24 2007
New Revision: 10016
Modified:
dbi/trunk/lib/DBD/Gofer/Transport/Base.pm
dbi/trunk/lib/DBI/Gofer/Transport/Base.pm
dbi/trunk/t/87gofer_cache.t
Log:
Assorted fixes for DBD::Gofer caching
Modified: dbi/trunk/lib/DBD/Gofer/Transport/Base.pm
==============================================================================
--- dbi/trunk/lib/DBD/Gofer/Transport/Base.pm (original)
+++ dbi/trunk/lib/DBD/Gofer/Transport/Base.pm Fri Sep 28 09:39:24 2007
@@ -35,6 +35,8 @@
sub new {
my ($class, $args) = @_;
$args->{$_} = 0 for (qw(cache_hit cache_miss cache_store));
+ $args->{keep_meta_frozen} ||= 1 if $args->{go_cache};
+ #warn "args @{[ %$args ]}\n";
return $class->SUPER::new($args);
}
@@ -141,12 +143,15 @@
}
} while ( $self->response_needs_retransmit($request, $response) );
- my $frozen_response = delete $response->{meta}{frozen}
- or warn "No meta frozen in request";
+ my $frozen_response = delete $response->{meta}{frozen};
+
+ if (my $go_cache = $self->{go_cache}) {
+
+ # new() ensures that enabling go_cache also enabled keep_meta_frozen
+ warn "No meta frozen in request" if !$frozen_response;
- if ($frozen_response and my $go_cache = $self->{go_cache}) {
my $request_key = $self->get_cache_key_for_request($request);
- if ($request_key) {
+ if ($frozen_response && $request_key) {
$self->trace_msg("receive_response added response to cache\n");
$go_cache->set($request_key, $frozen_response);
++$self->{cache_store};
Modified: dbi/trunk/lib/DBI/Gofer/Transport/Base.pm
==============================================================================
--- dbi/trunk/lib/DBI/Gofer/Transport/Base.pm (original)
+++ dbi/trunk/lib/DBI/Gofer/Transport/Base.pm Fri Sep 28 09:39:24 2007
@@ -36,7 +36,6 @@
my ($class, $args) = @_;
$args->{trace} ||= $class->_init_trace;
$args->{serializer_obj} ||= DBI::Gofer::Serializer::Storable->new();
- $args->{keep_meta_frozen} ||= 1 if $args->{go_cache};
my $self = bless {}, $class;
$self->$_( $args->{$_} ) for keys %$args;
$self->trace_msg("$class->new({ @{[ %$args ]} })\n") if $self->trace;
Modified: dbi/trunk/t/87gofer_cache.t
==============================================================================
--- dbi/trunk/t/87gofer_cache.t (original)
+++ dbi/trunk/t/87gofer_cache.t Fri Sep 28 09:39:24 2007
@@ -50,11 +50,12 @@
ok my $rows1 = $dbh->selectall_arrayref("select name from ?", {}, ".");
cmp_ok $cache_obj->count, '>', 0, 'cache should not be empty after select';
+ my $expected = ($ENV{DBI_AUTOPROXY}) ? 2 : 1;
is $go_transport->cache_hit, 0;
- is $go_transport->cache_miss, 1;
- is $go_transport->cache_store, 1;
+ is $go_transport->cache_miss, $expected;
+ is $go_transport->cache_store, $expected;
- is $go_transport->transmit_count, 1, 'should make 1 round trip';
+ is $go_transport->transmit_count, $expected, 'should make 1 round trip';
$go_transport->transmit_count(0);
is $go_transport->transmit_count, 0, 'transmit_count should be 0';
@@ -63,8 +64,10 @@
is_deeply $rows2, $rows1;
is $go_transport->transmit_count, 0, 'should make 1 round trip';
- is $go_transport->cache_hit, 1;
- is $go_transport->cache_miss, 1;
- is $go_transport->cache_store, 1;
+ is $go_transport->cache_hit, $expected;
+ is $go_transport->cache_miss, $expected;
+ is $go_transport->cache_store, $expected;
}
+
+1;