Memoize is a module for speeding up functions by automatically memoizing them. If you have a function and you want to make it faster, you can say memoize 'function'; and that will make it faster. (It might also make it return the wrong results, so read the manual before you do it.)
To join a low-volume mailing list for Memoize announcements, send a blank mail message to mjd-perl-memoize-subscribe@plover.com.
TIE option strongly deprecated in favor of HASH. Detailed information.
Various performance enhancements.
New flush_cache
function for explicitly
discarding cache
New HASH
option allows the user to explicitly
supply a hash which will be used for cached data storage
More error checking, larger test suite
Enhanced documentation
Minor test suite fix.
You can now expire data from the memoization cache according to any expiration policy you desire. A sample policy is provided in the Memoize::Expire module. It supports expiration of items that have been in the cache a certain number of seconds and items that have been accessed a certain number of times. When you call a memoized function, and Memoize discovers that a cache item has expired, it calls the real function and stores the result in the cache, just as if the data had not been in the cache in the first place.
Many people asked for a cache expiration feature, and some people even sent patches. Thanks for the patches! But I did not accept them, because they all added the expiration stuff into the module, and I was sure that this was a bad way to do it. Everyone had a different idea of what useful expiration behavior was, so I foresaw an endless series of creeeping features and an expiration mechansim that got more and more and more complicated and slower and slower and slower.
The new expiration policy mechanism makes use of the TIE feature. You write a cache policy module (which might be very simple) and use the TIE feature to insert it between Memoize and the real cache. The Memoize::Expire module. included in this package, is a useful example of this that might satisfy many people. The documentation for that module includes an even simpler module for those who would like to implement their own expiration policies.
Big win: If you don't use the expiration feature, you don't pay for it. Memoize 0.49 with expiration turned off runs exactly as fast as Memoize 0.48 did. Not one line of code has been changed.
Moral of the story: Sometimes, there is a Right Way to Do Things that really is better than the obvious way. It might not be obvious at first, and sometimes you have to make people wait for features so that the Right Way to Do Things can make itself known.
Many thanks to Mike Cariaso for helping me figure out The Right Way to Do Things.
If you try to use ODBM_File, NDBM_File, SDBM_File, GDBM_File, or DB_File for the LIST_CACHE, you get an error right away, because those kinds of files will only store strings. Thanks to Jonathan Roy for suggesting this. If you want to store list values in a persistent cache, try Memoize::Storable.
SCALAR_CACHE => [TIE, GDBM_File, './cache', O_RDWR|O_CREAT, 0666]
memoize(function, OPTION1 => VALUE1, ...)instead of
memoize(function, { OPTION1 => VALUE1, ... })
Return to: Universe of Discourse main page | What's new page | Perl Paraphernalia