Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

memoize::expirelru(3pm) [debian man page]

ExpireLRU(3pm)						User Contributed Perl Documentation					    ExpireLRU(3pm)

NAME
Memoize - Expiry plug-in for Memoize that adds LRU cache expiration SYNOPSIS
use Memoize; memoize('slow_function', TIE => [Memoize::ExpireLRU, CACHESIZE => n, ]); Note that one need not "use" this module. It will be found by the Memoize module. The argument to CACHESIZE must be an integer. Normally, this is all that is needed. Additional options are available: TUNECACHESIZE => m, INSTANCE => 'descriptive_name', TIE => '[DB_File, $filename, O_RDWR | O_CREATE, 0666]' DESCRIPTION
For the theory of Memoization, please see the Memoize module documentation. This module implements an expiry policy for Memoize that follows LRU semantics, that is, the last n results, where n is specified as the argument to the "CACHESIZE" parameter, will be cached. PERFORMANCE TUNING
It is often quite difficult to determine what size cache will give optimal results for a given function. To aid in determining this, ExpireLRU includes cache tuning support. Enabling this causes a definite performance hit, but it is often useful before code is released to production. To enable cache tuning support, simply specify the optional "TUNECACHESIZE" parameter with a size greater than that of the "CACHESIZE" parameter. When the program exits, a set of statistics will be printed to stderr. If multiple routines have been memoized, separate sets of statistics are printed for each routine. The default names are somewhat cryptic: this is the purpose of the "INSTANCE" parameter. The value of this parameter will be used as the identifier within the statistics report. DIAGNOSTIC METHODS
Two additional routines are available but not exported. Memoize::ExpireLRU::ShowStats returns a string identical to the statistics report printed to STDERR at the end of the program if test caches have been enabled; Memoize::ExpireLRU::DumpCache takes the instance name of a memoized function as a parameter, and returns a string describing the current state of that instance. AUTHOR
Brent B. Powers (B2Pi), Powers@B2Pi.com Copyright(c) 1999 Brent B. Powers. All rights reserved. This program is free software, you may redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Memoize perl v5.10.1 2000-04-12 ExpireLRU(3pm)

Check Out this Related Man Page

Tie::Memoize(3pm)					 Perl Programmers Reference Guide					 Tie::Memoize(3pm)

NAME
Tie::Memoize - add data to hash when needed SYNOPSIS
require Tie::Memoize; tie %hash, 'Tie::Memoize', &fetch, # The rest is optional $DATA, &exists, {%ini_value}, {%ini_existence}; DESCRIPTION
This package allows a tied hash to autoload its values on the first access, and to use the cached value on the following accesses. Only read-accesses (via fetching the value or "exists") result in calls to the functions; the modify-accesses are performed as on a normal hash. The required arguments during "tie" are the hash, the package, and the reference to the "FETCH"ing function. The optional arguments are an arbitrary scalar $data, the reference to the "EXISTS" function, and initial values of the hash and of the existence cache. Both the "FETCH"ing function and the "EXISTS" functions have the same signature: the arguments are "$key, $data"; $data is the same value as given as argument during tie()ing. Both functions should return an empty list if the value does not exist. If "EXISTS" function is different from the "FETCH"ing function, it should return a TRUE value on success. The "FETCH"ing function should return the intended value if the key is valid. Inheriting from Tie::Memoize The structure of the tied() data is an array reference with elements 0: cache of known values 1: cache of known existence of keys 2: FETCH function 3: EXISTS function 4: $data The rest is for internal usage of this package. In particular, if TIEHASH is overwritten, it should call SUPER::TIEHASH. EXAMPLE
sub slurp { my ($key, $dir) = shift; open my $h, '<', "$dir/$key" or return; local $/; <$h> # slurp it all } sub exists { my ($key, $dir) = shift; return -f "$dir/$key" } tie %hash, 'Tie::Memoize', &slurp, $directory, &exists, { fake_file1 => $content1, fake_file2 => $content2 }, { pretend_does_not_exists => 0, known_to_exist => 1 }; This example treats the slightly modified contents of $directory as a hash. The modifications are that the keys fake_file1 and fake_file2 fetch values $content1 and $content2, and pretend_does_not_exists will never be accessed. Additionally, the existence of known_to_exist is never checked (so if it does not exists when its content is needed, the user of %hash may be confused). BUGS
FIRSTKEY and NEXTKEY methods go through the keys which were already read, not all the possible keys of the hash. AUTHOR
Ilya Zakharevich mailto:perl-module-hash-memoize@ilyaz.org <mailto:perl-module-hash-memoize@ilyaz.org>. perl v5.16.2 2012-08-26 Tie::Memoize(3pm)
Man Page