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

Download:
Bot-Cobalt-0.016002.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.016002   Source  

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>

http://www.cobaltirc.org

syntax highlighting: