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

(-)a/Koha/Cache.pm (-18 / +17 lines)
Lines 281-294 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
    my $flag = '-CF0'; # 0: scalar, 1: freezed data structure
284
    my $flag = '-CF0'; # 0: scalar, 1: frozen data structure
285
    # Set in L1 cache
285
    # Set in L1 cache
286
    if (ref($value)) {
286
    if (ref($value)) {
287
        $value = freeze($value);
287
        $value = freeze($value);
288
        $L1_cache{ $key } = [ (undef, $value) ];
288
        $L1_cache{$key}->{frozen} = $value;
289
        $flag = '-CF1';
289
        $flag = '-CF1';
290
    } else {
290
    } else {
291
        $L1_cache{ $key } = $value;
291
        $L1_cache{$key} = $value;
292
    }
292
    }
293
293
294
    $value .= $flag;
294
    $value .= $flag;
Lines 331-365 sub get_from_cache { Link Here
331
    if ( exists $L1_cache{$key} ) {
331
    if ( exists $L1_cache{$key} ) {
332
        if (ref($L1_cache{$key})) {
332
        if (ref($L1_cache{$key})) {
333
            if ($unsafe) {
333
            if ($unsafe) {
334
                $L1_cache{$key}->[0] ||= thaw($L1_cache{$key}->[1]);
334
                $L1_cache{$key}->{thawed} ||= thaw($L1_cache{$key}->{frozen});
335
                return $L1_cache{$key}->[0];
335
                return $L1_cache{$key}->{thawed};
336
            } else {
336
            } else {
337
                return thaw($L1_cache{$key}->[1]);
337
                return thaw($L1_cache{$key}->{frozen});
338
            }
338
            }
339
        } else {
339
        } else {
340
            # No need to deep copy if it's a scalar
340
            # No need to thaw if it's a scalar
341
            return $L1_cache{$key};
341
            return $L1_cache{$key};
342
        }
342
        }
343
    }
343
    }
344
344
345
    my $get_sub = $self->{ref($self->{$cache}) . "_get"};
345
    my $get_sub = $self->{ref($self->{$cache}) . "_get"};
346
    my $value = $get_sub ? $get_sub->($key) : $self->{$cache}->get($key);
346
    my $L2_value = $get_sub ? $get_sub->($key) : $self->{$cache}->get($key);
347
347
348
    return if ref($value);
348
    return if ref($L2_value);
349
    return unless (defined($value) && length($value) >= 4);
349
    return unless (defined($L2_value) && length($L2_value) >= 4);
350
350
351
    my $flag = substr($value, -4, 4, '');
351
    my $flag = substr($L2_value, -4, 4, '');
352
    if ($flag eq '-CF0') {
352
    if ($flag eq '-CF0') {
353
        # it's a scalar
353
        # it's a scalar
354
        $L1_cache{$key} = $value;
354
        $L1_cache{$key} = $L2_value;
355
        return $value;
355
        return $L2_value;
356
    } elsif ($flag eq '-CF1') {
356
    } elsif ($flag eq '-CF1') {
357
        # it's a freezed data structure
357
        # it's a frozen data structure
358
        my $thawed;
358
        my $thawed;
359
        eval { $thawed = thaw($value); };
359
        eval { $thawed = thaw($L2_value); };
360
        return if $@;
360
        return if $@;
361
        $L1_cache{$key} = [ (undef, $value) ];
361
        $L1_cache{$key}->{frozen} = $L2_value;
362
        $L1_cache{$key}->[0] = $thawed if $unsafe;
362
        $L1_cache{$key}->{thawed} = $thawed if $unsafe;
363
        return $thawed;
363
        return $thawed;
364
    }
364
    }
365
365
366
- 

Return to bug 16166