Jon Portnoy > Bot-Cobalt > Bot::Cobalt::Plugin::RDB::SearchCache



Annotate this POD

View/Report Bugs
Module Version: 0.016002   Source  


Bot::Cobalt::Plugin::RDB::SearchCache - Simple in-memory cache


  ## 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:
  ## Invalidate one entry:
  $cache->invalidate('MyCache', $key);

  ## Change the maximum number of keys on the fly:
  ## ...or find out what the current max is:
  my $current_max = $cache->MaxKeys;


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.


Jon Portnoy <>

syntax highlighting: