amw1 has asked for the wisdom of the Perl Monks concerning the following question:

We were using memoize::expire to do some simple dns caching. I was using the example from the perldoc to setup persistant disk caching (code below)
# Code from the perldoc use Memoize; use Memoize::Expire; use DB_File; # Set up persistence tie my %disk_cache => 'DB_File', $filename, O_CREAT|O_RDWR, 0666]; # Set up expiration policy, supplying persistent hash as a target tie my %cache => 'Memoize::Expire', LIFETIME => $lifetime, # In seconds NUM_USES => $n_uses, HASH => \%disk_cache; # Set up memoization, supplying expiring persistent hash for cache memoize 'function', SCALAR_CACHE => [ HASH => \%cache ];
However, the TIEHASH routine in Memoize::Expire doesn't ever appear to do anything with the HASH argument. added this code near the bottom of TIEHASH in Memoize::Expire and this seemed to work
if(exists($args{HASH})) { $args{C} = $args{HASH}; } else { $args{C} = \%cache; }
I don't know if I was missing something in the docs but the above code seems to have fixed the problem.

Replies are listed 'Best First'.
Re: Possible bug in Memoize::Expire
by ikegami (Patriarch) on Mar 14, 2006 at 19:09 UTC

    I concur with your assessment.

    • You've clearly followed the example.

    • It doesn't appear to be an error in the documentation. It is clearly describing something which cannot be done without the code you specified.

    • $args{C} can accept an arbitrary hash instead reference as easily as the default anonymous one.

    I checked rt.cpan.org, and there's no bug report for it. This distribution's bug reports. U: So I've created one.

    By the way, I'd use $args{C} = $args{HASH} || \%cache; in case $args{HASH} exists, but isn't defined.

      I sent mail to the maintainer and opened a bug. FYI.