From bca183d72518e56c0f199092c939657d400134ce Mon Sep 17 00:00:00 2001 From: Jacek Ablewicz Date: Thu, 31 Mar 2016 17:09:28 +0200 Subject: [PATCH] Bug 16166: Try to improve code readability Test plan addendum #2: 6) Don't forget to flush L2 cache (restart mecached deameon) after testing as well - if you just return to master branch without this step, all sorts of weird things would happen --- Koha/Cache.pm | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Koha/Cache.pm b/Koha/Cache.pm index 5c918d0..2d05f81 100644 --- a/Koha/Cache.pm +++ b/Koha/Cache.pm @@ -281,14 +281,14 @@ sub set_in_cache { $expiry //= $self->{timeout}; my $set_sub = $self->{ref($self->{$cache}) . "_set"}; - my $flag = '-CF0'; # 0: scalar, 1: freezed data structure + my $flag = '-CF0'; # 0: scalar, 1: frozen data structure # Set in L1 cache if (ref($value)) { $value = freeze($value); - $L1_cache{ $key } = [ (undef, $value) ]; + $L1_cache{$key}->{frozen} = $value; $flag = '-CF1'; } else { - $L1_cache{ $key } = $value; + $L1_cache{$key} = $value; } $value .= $flag; @@ -331,35 +331,35 @@ sub get_from_cache { if ( exists $L1_cache{$key} ) { if (ref($L1_cache{$key})) { if ($unsafe) { - $L1_cache{$key}->[0] ||= thaw($L1_cache{$key}->[1]); - return $L1_cache{$key}->[0]; + $L1_cache{$key}->{thawed} ||= thaw($L1_cache{$key}->{frozen}); + return $L1_cache{$key}->{thawed}; } else { - return thaw($L1_cache{$key}->[1]); + return thaw($L1_cache{$key}->{frozen}); } } else { - # No need to deep copy if it's a scalar + # No need to thaw if it's a scalar return $L1_cache{$key}; } } my $get_sub = $self->{ref($self->{$cache}) . "_get"}; - my $value = $get_sub ? $get_sub->($key) : $self->{$cache}->get($key); + my $L2_value = $get_sub ? $get_sub->($key) : $self->{$cache}->get($key); - return if ref($value); - return unless (defined($value) && length($value) >= 4); + return if ref($L2_value); + return unless (defined($L2_value) && length($L2_value) >= 4); - my $flag = substr($value, -4, 4, ''); + my $flag = substr($L2_value, -4, 4, ''); if ($flag eq '-CF0') { # it's a scalar - $L1_cache{$key} = $value; - return $value; + $L1_cache{$key} = $L2_value; + return $L2_value; } elsif ($flag eq '-CF1') { - # it's a freezed data structure + # it's a frozen data structure my $thawed; - eval { $thawed = thaw($value); }; + eval { $thawed = thaw($L2_value); }; return if $@; - $L1_cache{$key} = [ (undef, $value) ]; - $L1_cache{$key}->[0] = $thawed if $unsafe; + $L1_cache{$key}->{frozen} = $L2_value; + $L1_cache{$key}->{thawed} = $thawed if $unsafe; return $thawed; } -- 1.7.10.4