Subject: | Bug in Cache::Memory regarding Namespaces |
I've just written my first app that uses Cache, so I'm new to this, but,
here's my issue:
I have one cache that I need to keep three versions of data in. I use
the version number as the namespace, but I don't know the version
numbers in advance. The bug is that when you call set_namespace, it
assumes the two heaps have already been setup for that namespace.
Here's a test case:
use Cache::Memory;
my $cache = Cache::Memory->new();
#this works:
$cache->set('foo','bar');
$cache->set_namespace("OtherNameSpace");
#This dies:
$cache->set('foo','bar2');
Changing the set_namespace method in Memory.pm to this:
sub set_namespace {
my Cache::Memory $self = shift;
my ($namespace) = @_;
$Age_Heaps{$namespace} ||= Heap::Fibonacci->new();
$Use_Heaps{$namespace} ||= Heap::Fibonacci->new();
$self->{namespace} = $namespace;
}
Makes it work fine.