Bugzilla – Attachment 50199 Details for
Bug 16229
Koha::Cache should be on the safe side
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16229: Deep copy on first L2 fetch
Bug-16229-Deep-copy-on-first-L2-fetch.patch (text/plain), 2.04 KB, created by
Jacek Ablewicz
on 2016-04-13 14:48:53 UTC
(
hide
)
Description:
Bug 16229: Deep copy on first L2 fetch
Filename:
MIME Type:
Creator:
Jacek Ablewicz
Created:
2016-04-13 14:48:53 UTC
Size:
2.04 KB
patch
obsolete
>From b80b95241e2dc4fa806eea4ed040ecf35577d3fb Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 8 Apr 2016 13:08:55 +0100 >Subject: [PATCH] Bug 16229: Deep copy on first L2 fetch > >When a value exists in L2 cache but not in L1 cache, it should be deep >copied if needed (i.e. not a scalar). Otherwise the calling code is able >to modify the value in cache. >Note that is theoretical, it's possible that no code does that. > >Signed-off-by: Jacek Ablewicz <abl@biblos.pk.edu.pl> >--- > Koha/Cache.pm | 2 ++ > t/Cache.t | 8 +++++++- > 2 files changed, 9 insertions(+), 1 deletion(-) > >diff --git a/Koha/Cache.pm b/Koha/Cache.pm >index 8370d3e..0c9558d 100644 >--- a/Koha/Cache.pm >+++ b/Koha/Cache.pm >@@ -335,6 +335,8 @@ sub get_from_cache { > # Otherwise the L1 cache won't ever be populated > $L1_cache{$key} = $value; > >+ $value = clone $value if ref $L1_cache{$key} and not $unsafe; >+ > return $value; > } > >diff --git a/t/Cache.t b/t/Cache.t >index 8adaf1c..fa20a45 100644 >--- a/t/Cache.t >+++ b/t/Cache.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 37; >+use Test::More tests => 38; > > my $destructorcount = 0; > >@@ -181,6 +181,12 @@ SKIP: { > $item_from_cache = $cache->get_from_cache('test_deep_copy_array'); > @$item_from_cache = qw( another array ref ); > is_deeply( $cache->get_from_cache('test_deep_copy_array'), [ qw ( an array ref ) ], 'An array will be deep copied'); >+ >+ $cache->flush_L1_cache(); >+ $item_from_cache = $cache->get_from_cache('test_deep_copy_array'); >+ @$item_from_cache = qw( another array ref ); >+ is_deeply( $cache->get_from_cache('test_deep_copy_array'), [ qw ( an array ref ) ], 'An array will be deep copied even it is the first fetch from L2'); >+ > $item_from_cache = $cache->get_from_cache('test_deep_copy_array', { unsafe => 1 }); > @$item_from_cache = qw( another array ref ); > is_deeply( $cache->get_from_cache('test_deep_copy_array'), [ qw ( another array ref ) ], 'An array will not be deep copied if the unsafe flag is set'); >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16229
:
50072
|
50073
|
50074
|
50076
|
50199
|
50200
|
50201
|
50235
|
50236
|
50237
|
50238