CHI::Memoize

Make functions faster with memoization, via CHI
Download

CHI::Memoize Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Jonathan Swartz
  • Publisher web site:
  • http://search.cpan.org/~jswartz/

CHI::Memoize Tags


CHI::Memoize Description

Memoizing is a function that makes it faster by trading space for time. It does this by caching the return values of the function in a table. If you call the function again with the same arguments, memoize jumps in and gives you the value out of the table, instead of letting the function compute the value all over again." -- quoted from the original MemoizeCHI::Memoize is a Perl module that provides the same facility as Memoize, but backed by CHI. This means, among other things, that you can- specify expiration times (expires_in) and conditions (expire_if)- memoize to different backends, e.g. File, Memcached, DBI, or to multilevel caches- handle arbitrarily complex function arguments (via CHI key serialization)SYNOPSIS use CHI::Memoize qw(:all); # Straight memoization in memory memoize('func'); memoize('Some::Package::func'); # Memoize an anonymous function $anon = memoize($anon); # Memoize based on the second and third argument to func memoize('func', key => sub { $_, $_ }); # Memoize only in certain cases memoize('func', key => sub { $_ eq 'variable' ? NO_MEMOIZE : @_ }); # Expire after one hour memoize('func', expires_in => '1h'); # Store a maximum of 10 results with LRU discard memoize('func', max_size => 10); # Store raw references instead of serializing/deserializing (faster, more risky) memoize('func', driver => 'RawMemory'); # Store in memcached instead of memory memoize('func', driver => 'Memcached', servers => ); # See what's been memoized for a function my @keys = memoized('func')->cache->get_keys; # Clear memoize results for a function my @keys = memoized('func')->cache->clear; # Use an explicit cache instead of autocreating one my $cache = CHI->new(driver => 'Memcached', servers => ); memoize('func', cache => $cache); # Unmemoize function, restoring it to its original state unmemoize('func');Product's homepage


CHI::Memoize Related Software