1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
# so we don't need the Cache::* family installed just to make test...
# lowering the barrier to others hacking on this stuff.
package Cache::Memory;
use strict;
use Storable;
sub new {
my $class = shift;
return bless {}, $class;
}
sub remove {
my ($self, $key) = @_;
delete $self->{$key};
}
sub thaw {
my ($self, $key) = @_;
my $val = $self->{$key};
return unless defined $val;
my $magic = eval { Storable::read_magic($val); };
if ($magic && $magic->{major} && $magic->{major} >= 2) {
return Storable::thaw($val);
}
return $val;
}
sub freeze {
my ($self, $key, $val) = @_;
$self->{$key} = ref($val) ? Storable::freeze($val) : $val;
return 1;
}
1;
|