in reply to Memoizing Methods

What about just using Cache::FileCache or similar?
use Cache::FileCache; sub methodname { my $self = shift; my $value = shift; # optional my $cacheKey = "methodname - $self'; # or use $self->id or similar +if there is one -- just something unique for this method & instance my $cache = new Cache::FileCache( { namespace=>"YourStuff" } ); if( defined $value ){ $cache->set( $cacheKey, $value, "10 minutes" ); # this could be N +EVER_EXPIRE, too } my $result = $cache->get($key); return $result if defined $result; # do actual 'methodname' calculations here. # optionally cache the result: # $cache->set( $cacheKey, $value, "10 minutes" ); }

Replies are listed 'Best First'.
Re^2: Memoizing Methods
by bduggan (Pilgrim) on Mar 29, 2006 at 17:24 UTC
    I'd like to factor out the caching part, since that'll be common to all the methods. But, thanks -- Cache::MemoryCache does seem to be a handy module to use within setupMemoizedSubs().