Memoize::Expire

Plug-in module for automatic expiration of memoized values
Download

Memoize::Expire Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Mark Jason Dominus
  • Publisher web site:
  • http://search.cpan.org/~mjd/

Memoize::Expire Tags


Memoize::Expire Description

Plug-in module for automatic expiration of memoized values Memoize::Expire is a plug-in module for automatic expiration of memoized values.SYNOPSIS use Memoize; use Memoize::Expire; tie my che => 'Memoize::Expire', LIFETIME => $lifetime, # In seconds NUM_USES => $n_uses; memoize 'function', SCALAR_CACHE => ;Memoize::Expire is a plug-in module for Memoize. It allows the cached values for memoized functions to expire automatically. This manual assumes you are already familiar with the Memoize module. If not, you should study that manual carefully first, paying particular attention to the HASH feature.Memoize::Expire is a layer of software that you can insert in between Memoize itself and whatever underlying package implements the cache. The layer presents a hash variable whose values expire whenever they get too old, have been used too often, or both. You tell Memoize to use this forgetful hash as its cache instead of the default, which is an ordinary hash.To specify a real-time timeout, supply the LIFETIME option with a numeric value. Cached data will expire after this many seconds, and will be looked up afresh when it expires. When a data item is looked up afresh, its lifetime is reset.If you specify NUM_USES with an argument of n, then each cached data item will be discarded and looked up afresh after the nth time you access it. When a data item is looked up afresh, its number of uses is reset.If you specify both arguments, data will be discarded from the cache when either expiration condition holds.Memoize::Expire uses a real hash internally to store the cached data. You can use the HASH option to Memoize::Expire to supply a tied hash in place of the ordinary hash that Memoize::Expire will normally use. You can use this feature to add Memoize::Expire as a layer in between a persistent disk hash and Memoize. If you do this, you get a persistent disk cache whose entries expire automatically. For example: # Memoize # | # Memoize::Expire enforces data expiration policy # | # DB_File implements persistence of data in a disk file # | # Disk file 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 che => '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 => ; Requirements: · Perl


Memoize::Expire Related Software