To avoid the cache to be modified unfortunately, the default behavior of
get_from_cache will be to deep copy if we are getting a structure.
If the item is a scalar, it's simply returned.
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
use strict;
use warnings;
use Carp;
+use Clone qw( clone );
use Module::Load::Conditional qw(can_load);
use Koha::Cache::Object;
return unless ( $self->{$cache} && ref( $self->{$cache} ) =~ m/^Cache::/ );
# Return L1 cache value if exists
- return $L1_cache{$key} if exists $L1_cache{$key};
+ if ( exists $L1_cache{$key} ) {
+ # No need to deep copy if it's a scalar:
+ return $L1_cache{$key}
+ unless ref $L1_cache{$key};
+ return clone $L1_cache{$key};
+ }
my $get_sub = $self->{ref($self->{$cache}) . "_get"};
return $get_sub ? $get_sub->($key) : $self->{$cache}->get($key);