Why not adopt me?
This distribution is up for adoption!
If you're interested then please contact the PAUSE module admins via
email.
NAME
Bot::Cobalt::Plugin::RDB::SearchCache - Simple in-memory cache
SYNOPSIS
## Add a SearchCache that allows 30 max keys:
$self->{CacheObj} = Bot::Cobalt::Plugin::RDB::SearchCache->new(
MaxKeys => 30,
);
## Save some array of results/indexes to the cache obj:
my $cache = $self->{CacheObj};
$cache->cache('MyCache', $key, [ @results ] );
## Get it back later:
my @results = $cache->fetch('MyCache', $key);
## ...or get the reference to the actual array:
my $resultset = $cache->fetch('MyCache', $key);
## Data changed, invalidate this cache:
$cache->invalidate('MyCache');
## Invalidate one entry:
$cache->invalidate('MyCache', $key);
## Change the maximum number of keys on the fly:
$cache->MaxKeys('40');
## ...or find out what the current max is:
my $current_max = $cache->MaxKeys;
DESCRIPTION
SearchCache is a very simplistic mechanism for storing some arrays of data in a hash with a set ceiling limit of keys.
If the number of keys in the specified cache grows above MaxKeys, older entries will be removed from the hash to make room for the new set.
This can be useful for caching the result of deep searches against large Bot::Cobalt::DB databases, for example.
This interface is used by Bot::Cobalt::Plugin::RDB and Bot::Cobalt::Plugin::Info3.
AUTHOR
Jon Portnoy <avenj@cobaltirc.org>