use strict;
use warnings;
use Carp;
-use Storable qw(freeze thaw);
use Module::Load::Conditional qw(can_load);
use Koha::Cache::Object;
+use Sereal;
use base qw(Class::Accessor);
qw( cache memcached_cache fastmmap_cache memory_cache ));
our %L1_cache;
+our $L1_encoder = Sereal::Encoder->new;
+our $L1_decoder = Sereal::Decoder->new;
=head2 get_instance
my $flag = '-CF0'; # 0: scalar, 1: frozen data structure
if (ref($value)) {
# Set in L1 cache as a data structure, initially only in frozen form (for performance reasons)
- $value = freeze($value);
+ $value = $L1_encoder->encode($value);
$L1_cache{$key}->{frozen} = $value;
$flag = '-CF1';
} else {
if ( exists $L1_cache{$key} ) {
if (ref($L1_cache{$key})) {
if ($unsafe) {
- $L1_cache{$key}->{thawed} ||= thaw($L1_cache{$key}->{frozen});
+ $L1_cache{$key}->{thawed} ||= $L1_decoder->decode($L1_cache{$key}->{frozen});
return $L1_cache{$key}->{thawed};
} else {
- return thaw($L1_cache{$key}->{frozen});
+ return $L1_decoder->decode($L1_cache{$key}->{frozen});
}
} else {
# No need to thaw if it's a scalar
} elsif ($flag eq '-CF1') {
# it's a frozen data structure
my $thawed;
- eval { $thawed = thaw($L2_value); };
+ eval { $thawed = $L1_decoder->decode($L2_value); };
return if $@;
$L1_cache{$key}->{frozen} = $L2_value;
$L1_cache{$key}->{thawed} = $thawed if $unsafe;