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

(-)a/Koha/Cache.pm (-1 / +3 lines)
Lines 281-287 sub set_in_cache { Link Here
281
    $expiry //= $self->{timeout};
281
    $expiry //= $self->{timeout};
282
    my $set_sub = $self->{ref($self->{$cache}) . "_set"};
282
    my $set_sub = $self->{ref($self->{$cache}) . "_set"};
283
283
284
    $value = clone $value;
284
    # Deep copy if it's not a scalar and unsafe is not passed
285
    $value = clone $value unless ref($value) and defined $options and $options->{unsafe};
286
285
    # Set in L1 cache
287
    # Set in L1 cache
286
    $L1_cache{ $key } = $value;
288
    $L1_cache{ $key } = $value;
287
289
(-)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