bump version
[dbsrgits/DBIx-Class-Cursor-Cached.git] / lib / DBIx / Class / Cursor / Cached.pm
index 70bd04a..16c8eb5 100644 (file)
@@ -2,14 +2,14 @@ package DBIx::Class::Cursor::Cached;
 
 use strict;
 use warnings;
-use 5.6.1;
+use 5.008001;
 use Storable ();
-use Digest::SHA1 ();
+use Digest::SHA ();
 use Carp::Clan qw/^DBIx::Class/;
 
 use vars qw($VERSION);
 
-$VERSION = '1.000001';
+$VERSION = '1.001004';
 
 sub new {
   my $class = shift;
@@ -54,24 +54,24 @@ sub _build_cache_key {
   # and not any other cruft in $attrs
   my $ref = $storage->_select_args_to_query(@{$args}[0..2], $attrs);
 
-  my ($connect_info, $dbname, $username);
-  $connect_info = $storage->_dbi_connect_info;
-  if (my $dbh = $storage->_dbh) {
-    $dbname = $dbh->{Name};
-    $username = $dbh->{Username} || '';
-  } elsif (! ref($connect_info->[0]) ) {
-    $dbname = $connect_info->[0];
-    $username = $connect_info->[1] || '';
-  } else {
-    carp "Invoking connector coderef $connect_info->[0] in order to obtain cache-lookup information";
-    my $dbh = $connect_info->[0]->();
-    $dbname = $dbh->{Name};
-    $username = $dbh->{Username} || '';
+  my $conn;
+  if (! ($conn = $storage->_dbh) ) {
+    my $connect_info = $storage->_dbi_connect_info;
+    if (! ref($connect_info->[0]) ) {
+      $conn = { Name => $connect_info->[0], Username => $connect_info->[1] };
+    } else {
+      carp "Invoking connector coderef $connect_info->[0] in order to obtain cache-lookup information";
+      $conn = $connect_info->[0]->();
+    }
   }
-  
-  local $Storable::canonical = 1;
-  return Digest::SHA1::sha1_hex(Storable::nfreeze( [ $ref, $dbname, $username ] ));
 
+  return $class->_build_cache_key_hash([ $ref, $conn->{Name}, $conn->{Username} || '' ]);
+}
+
+sub _build_cache_key_hash {
+  my ($class, $key_data) = @_;
+  local $Storable::canonical = 1;
+  return Digest::SHA::sha1_hex(Storable::nfreeze( $key_data ));
 }
 
 sub _fill_data {
@@ -79,12 +79,17 @@ sub _fill_data {
   my $cache = $self->{cache_object};
   my $key = $self->{cache_key};
   return $cache->get($key) || do {
-    my $data = [ $self->{inner}->all ];
+    my $data = $self->_fill_data_fetch_all();
     $cache->set($key, $data, $self->{cache_for});
     $data;
   };
 }
 
+sub _fill_data_fetch_all {
+    my ($self) = @_;
+    return [ $self->{inner}->all ];
+}
+
 sub clear_cache {
   my ($self) = @_;
   $self->{cache_object}->remove($self->{cache_key});