From f41284572093c2b3a96152792f287a63ecbd74b5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 18 Jun 2016 15:01:51 +0100 Subject: [PATCH] Bug 16769: Uniformise calls to Koha::Cache->set_in_cache From the POD of Koha::Cache->set_in_cache: # This is a bit of a hack to support the old API in case things still use it Let's remove this hack and update old calls. Test plan: Look at the results of git grep set_in_cache and confirm that there are no more version of the old call (without hashref as third param) Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens --- Koha/Cache.pm | 11 +++-------- Koha/Calendar.pm | 2 +- Koha/MetaSearcher.pm | 2 +- t/Cache.t | 6 +++--- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Koha/Cache.pm b/Koha/Cache.pm index 08577bd..80ff1ca 100644 --- a/Koha/Cache.pm +++ b/Koha/Cache.pm @@ -244,14 +244,9 @@ instance of C and follow the same interface as L. =cut sub set_in_cache { - my ( $self, $key, $value, $options, $_cache) = @_; - # This is a bit of a hack to support the old API in case things still use it - if (defined $options && (ref($options) ne 'HASH')) { - my $new_options; - $new_options->{expiry} = $options; - $new_options->{cache} = $_cache if defined $_cache; - $options = $new_options; - } + my ( $self, $key, $value, $options ) = @_; + + my $unsafe = $options->{unsafe} || 0; # the key mustn't contain whitespace (or control characters) for memcache # but shouldn't be any harm in applying it globally. diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 0065044..eed55cb 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -125,7 +125,7 @@ sub single_holidays { $single_holidays->{$br} = \@ymd_arr; } # br $cache->set_in_cache( 'single_holidays', $single_holidays, - 76800 ) #24 hrs ; + { expiry => 76800 } ) #24 hrs ; } my $holidays = ( $single_holidays->{$branchcode} ); for my $hols (@$holidays ) { diff --git a/Koha/MetaSearcher.pm b/Koha/MetaSearcher.pm index ce5add4..65f7239 100644 --- a/Koha/MetaSearcher.pm +++ b/Koha/MetaSearcher.pm @@ -172,7 +172,7 @@ sub search { hits => $result->{hits}, num_fetched => $result->{num_fetched}, num_hits => $result->{num_hits}, - }, $resultset_expiry ); + }, { expiry => $resultset_expiry } ); } } } diff --git a/t/Cache.t b/t/Cache.t index be36a80..3af4f6f 100644 --- a/t/Cache.t +++ b/t/Cache.t @@ -54,16 +54,16 @@ SKIP: { } # test expiry time in cache - $cache->set_in_cache( "timeout", "I AM DATA", 1 ); # expiry time of 1 second + $cache->set_in_cache( "timeout", "I AM DATA", { expiry => 1 } ); # expiry time of 1 second sleep 2; $cache->flush_L1_cache(); is( $cache->get_from_cache("timeout"), undef, "fetching expired item from cache" ); # test fetching a valid, non expired, item from cache - $cache->set_in_cache( "clear_me", "I AM MORE DATA", 1000 ) + $cache->set_in_cache( "clear_me", "I AM MORE DATA", { expiry => 1000 } ) ; # overly large expiry time, clear below - $cache->set_in_cache( "dont_clear_me", "I AM MORE DATA22", 1000 ) + $cache->set_in_cache( "dont_clear_me", "I AM MORE DATA22", { expiry => 1000 } ) ; # overly large expiry time, clear below is( $cache->get_from_cache("clear_me"), -- 2.1.4