Bug 16229: Add the unsafe flag to set_in_cache
Could be useful later.
Signed-off-by: Jacek Ablewicz <abl@biblos.pk.edu.pl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
Signed-off-by: Brendan Gallagher <bredan@bywatersolutions.com>
(cherry picked from commit 22c907230a)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
This commit is contained in:
parent
a54774cbf2
commit
2430d35926
|
|
@ -253,6 +253,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.
|
||||
|
|
@ -267,7 +268,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;
|
||||
|
||||
|
|
|
|||
11
t/Cache.t
11
t/Cache.t
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 41;
|
||||
use Test::More tests => 42;
|
||||
|
||||
my $destructorcount = 0;
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ SKIP: {
|
|||
$ENV{ MEMCACHED_NAMESPACE } = 'unit_tests';
|
||||
my $cache = Koha::Cache->get_instance();
|
||||
|
||||
skip "Cache not enabled", 35
|
||||
skip "Cache not enabled", 36
|
||||
unless ( $cache->is_cache_active() && defined $cache );
|
||||
|
||||
# test fetching an item that isnt in the cache
|
||||
|
|
@ -197,8 +197,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');
|
||||
|
|
|
|||
Loading…
Reference in New Issue