Bugzilla – Attachment 50076 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: Add the unsafe flag to set_in_cache
Bug-16229-Add-the-unsafe-flag-to-setincache.patch (text/plain), 2.38 KB, created by
Jonathan Druart
on 2016-04-08 12:35:27 UTC
(
hide
)
Description:
Bug 16229: Add the unsafe flag to set_in_cache
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-04-08 12:35:27 UTC
Size:
2.38 KB
patch
obsolete
>From f60cbe0b066d13284a2a9d8f051a8c65753155e4 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 8 Apr 2016 12:54:44 +0100 >Subject: [PATCH] Bug 16229: Add the unsafe flag to set_in_cache > >Could be useful later. >--- > Koha/Cache.pm | 5 ++++- > t/Cache.t | 9 ++++++++- > 2 files changed, 12 insertions(+), 2 deletions(-) > >diff --git a/Koha/Cache.pm b/Koha/Cache.pm >index c717c5a..7e8970d 100644 >--- a/Koha/Cache.pm >+++ b/Koha/Cache.pm >@@ -267,6 +267,7 @@ sub set_in_cache { > $new_options->{cache} = $_cache if defined $_cache; > $options = $new_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. >@@ -281,7 +282,9 @@ sub set_in_cache { > $expiry //= $self->{timeout}; > my $set_sub = $self->{ref($self->{$cache}) . "_set"}; > >- $value = clone $value; >+ # Deep copy if it's not a scalar and unsafe is not passed >+ $value = clone( $value ) if ref($value) and not $unsafe; >+ > # Set in L1 cache > $L1_cache{ $key } = $value; > >diff --git a/t/Cache.t b/t/Cache.t >index 8fa96e6..5a5c248 100644 >--- a/t/Cache.t >+++ b/t/Cache.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 39; >+use Test::More tests => 40; > > my $destructorcount = 0; > >@@ -196,8 +196,15 @@ SKIP: { > $item_from_cache = $cache->get_from_cache('test_deep_copy_hash'); > %$item_from_cache = ( another => 'hashref' ); > is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { a => 'hashref' }, 'A hash will be deep copied'); >+ > %item = ( a_modified => 'hashref' ); > is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { a => 'hashref' }, 'A hash will be deep copied when set in cache'); >+ >+ %item = ( a => 'hashref' ); >+ $cache->set_in_cache('test_deep_copy_hash', \%item, { unsafe => 1}); >+ %item = ( a_modified => 'hashref' ); >+ is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { a_modified => 'hashref' }, 'A hash will not be deep copied when set in cache if the unsafe flag is set'); >+ > $item_from_cache = $cache->get_from_cache('test_deep_copy_hash', { unsafe => 1}); > %$item_from_cache = ( another => 'hashref' ); > is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { another => 'hashref' }, 'A hash will not be deep copied if the unsafe flag is set'); >-- >2.7.0
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