in reply to Memoizing Methods
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 |