Browse Source

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 <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
16.11.x
Jonathan Druart 8 years ago
committed by Brendan Gallagher
parent
commit
7aacc32db8
  1. 11
      Koha/Cache.pm
  2. 2
      Koha/Calendar.pm
  3. 2
      Koha/MetaSearcher.pm
  4. 6
      t/Cache.t

11
Koha/Cache.pm

@ -244,14 +244,9 @@ instance of C<Cache::*> and follow the same interface as L<Cache::Memcache>.
=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.

2
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 ) {

2
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 } );
}
}
}

6
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"),

Loading…
Cancel
Save