Cache::Weak - weak reference cache
This documentation refers to Cache::Weak version 1.0.2
use Cache::Weak; my $cache = Cache::Weak->new();
This cache will store it's objects without increase the reference count. This can be used for caching without interfere in objects DESTROY mechanism, since the reference in this cache won't count.
You can pass a number of options to the constructor to specify things like namespace, etc. This is done by passing an inline hash (or hashref):
my $cache = Cache::Weak->new( namespace => 'foo' );
See "PROPERTIES" below for a list of all available properties that can be set.
Store specified key/value pair in cache. Value must be a reference.
my $object = $cache->get($key);
Search cache for given key. Returns undef if not found.
my $bool = $cache->exists($key);
Returns a boolean value to indicate whether there is any data present in the cache for specified entry.
Clear the data for specified entry from the cache.
Weak references are not removed from the cache when last "real" object goes out of scope. This means that over time the cache will grow in memory.
purge() will remove all dead references from cache. Usually you don't have to run
purge() manually: purging is done automatically. By default, this happens every 1000 object loads, but you can change that default by setting the 'auto_purge_interval' and 'auto_purge' properties.
Removes all entries from cache.
Returns the number of entries in the cache.
my $current_ns = $cache->namespace();
The namespace associated with this cache. Defaults to "_" if not explicitly set.
Sets number of cache object loads before auto purging is automatically performed. Default is 1000.
$cache->auto_purge(0); # turn off auto purge
If this option is true, then the auto purge interval will be checked on every
This module requires weak references support in your system. To find out if your system supports weak references, you can run this on the command line:
perl -e 'use Scalar::Util qw(weaken)'
If you get an error message about weak references not being implemented, this module would not work.
http://github.com/esobchenko/cache-weak/ this module on GitHub.
http://en.wikipedia.org/wiki/Weak_reference about weak references.
Scalar::Util for information about weak references in Perl.
Object::Mapper for an example of this module in use.
Copyright 2008, Eugen Sobchenko <email@example.com>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.