View | Details | Raw Unified | Return to bug 16229
Collapse All | Expand All

(-)a/Koha/Cache.pm (-1 / +4 lines)
Lines 267-272 sub set_in_cache { Link Here
267
        $new_options->{cache} = $_cache if defined $_cache;
267
        $new_options->{cache} = $_cache if defined $_cache;
268
        $options = $new_options;
268
        $options = $new_options;
269
    }
269
    }
270
    my $unsafe = $options->{unsafe} || 0;
270
271
271
    # the key mustn't contain whitespace (or control characters) for memcache
272
    # the key mustn't contain whitespace (or control characters) for memcache
272
    # but shouldn't be any harm in applying it globally.
273
    # but shouldn't be any harm in applying it globally.
Lines 281-287 sub set_in_cache { Link Here
281
    $expiry //= $self->{timeout};
282
    $expiry //= $self->{timeout};
282
    my $set_sub = $self->{ref($self->{$cache}) . "_set"};
283
    my $set_sub = $self->{ref($self->{$cache}) . "_set"};
283
284
284
    $value = clone $value;
285
    # Deep copy if it's not a scalar and unsafe is not passed
286
    $value = clone( $value ) if ref($value) and not $unsafe;
287
285
    # Set in L1 cache
288
    # Set in L1 cache
286
    $L1_cache{ $key } = $value;
289
    $L1_cache{ $key } = $value;
287
290
(-)a/t/Cache.t (-2 / +8 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 39;
20
use Test::More tests => 40;
21
21
22
my $destructorcount = 0;
22
my $destructorcount = 0;
23
23
Lines 196-203 SKIP: { Link Here
196
    $item_from_cache = $cache->get_from_cache('test_deep_copy_hash');
196
    $item_from_cache = $cache->get_from_cache('test_deep_copy_hash');
197
    %$item_from_cache = ( another => 'hashref' );
197
    %$item_from_cache = ( another => 'hashref' );
198
    is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { a => 'hashref' }, 'A hash will be deep copied');
198
    is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { a => 'hashref' }, 'A hash will be deep copied');
199
199
    %item = ( a_modified => 'hashref' );
200
    %item = ( a_modified => 'hashref' );
200
    is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { a => 'hashref' }, 'A hash will be deep copied when set in cache');
201
    is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { a => 'hashref' }, 'A hash will be deep copied when set in cache');
202
203
    %item = ( a => 'hashref' );
204
    $cache->set_in_cache('test_deep_copy_hash', \%item, { unsafe => 1});
205
    %item = ( a_modified => 'hashref' );
206
    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');
207
201
    $item_from_cache = $cache->get_from_cache('test_deep_copy_hash', { unsafe => 1});
208
    $item_from_cache = $cache->get_from_cache('test_deep_copy_hash', { unsafe => 1});
202
    %$item_from_cache = ( another => 'hashref' );
209
    %$item_from_cache = ( another => 'hashref' );
203
    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');
210
    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');
204
- 

Return to bug 16229