Bug 16769: Uniformise calls to Koha::Cache->set_in_cache
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 18 Jun 2016 14:01:51 +0000 (15:01 +0100)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Mon, 10 Oct 2016 17:03:54 +0000 (17:03 +0000)
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>
Koha/Cache.pm
Koha/Calendar.pm
Koha/MetaSearcher.pm
t/Cache.t

index 08577bd..80ff1ca 100644 (file)
@@ -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.
index 0065044..eed55cb 100644 (file)
@@ -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 ) {
index ce5add4..65f7239 100644 (file)
@@ -172,7 +172,7 @@ sub search {
                     hits => $result->{hits},
                     num_fetched => $result->{num_fetched},
                     num_hits => $result->{num_hits},
-                }, $resultset_expiry );
+                }, { expiry => $resultset_expiry } );
             }
         }
     }
index be36a80..3af4f6f 100644 (file)
--- 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"),