From: Tim Bunce Date: Fri, 20 Feb 2015 01:28:07 +0000 (+0000) Subject: Refactor slightly to enable useful subclassing X-Git-Tag: 1.1.3~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9f0680b8f12c134caf22bbc8bab5a4e402615963;p=dbsrgits%2FDBIx-Class-Cursor-Cached.git Refactor slightly to enable useful subclassing --- diff --git a/Changes b/Changes index 6a47e74..3ce99dc 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class::Cursor::Cached + - Refactor slightly to enable useful subclassing (RT#102223, Tim Bunce) + 1.1.2 5 August 2011 15:47:00 - use Digest::SHA over Digest::SHA1 since it is core, RT #70092 (Salvatore Bonaccorso) diff --git a/lib/DBIx/Class/Cursor/Cached.pm b/lib/DBIx/Class/Cursor/Cached.pm index 08fc6dd..9a8c64f 100644 --- a/lib/DBIx/Class/Cursor/Cached.pm +++ b/lib/DBIx/Class/Cursor/Cached.pm @@ -64,10 +64,14 @@ sub _build_cache_key { $conn = $connect_info->[0]->(); } } - - local $Storable::canonical = 1; - return Digest::SHA::sha1_hex(Storable::nfreeze( [ $ref, $conn->{Name}, $conn->{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 { @@ -75,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});