From 2e0af6e6df279aa08603e9696d35fc7def7bd7d3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Mar 2016 16:17:32 +0000 Subject: [PATCH] Bug 16044: Add deep cloning 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 Signed-off-by: Tomas Cohen Arazi Signed-off-by: Brendan A Gallagher --- Koha/Cache.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Koha/Cache.pm b/Koha/Cache.pm index 39a16d08c0..f389395090 100644 --- a/Koha/Cache.pm +++ b/Koha/Cache.pm @@ -38,6 +38,7 @@ The first, traditional OO interface provides the following functions: use strict; use warnings; use Carp; +use Clone qw( clone ); use Module::Load::Conditional qw(can_load); use Koha::Cache::Object; @@ -313,7 +314,12 @@ sub get_from_cache { 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); -- 2.39.5