The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Db::Mediasurface::Cache - caches a specified number of key-value pairs, disgarding underused pairs.

VERSION

This document refers to version 0.01 of DB::Mediasurface::Cache, released July 23, 2001.

SYNOPSIS

use Db::Mediasurface::Cache; my $cache = Db::Mediasurface::Cache->new(size=>1000);

# in your event loop... my $url = 'http://some.site.com/some/path?view=edititem&version=2'; my $id = undef; unless (defined ($id = $cache->get($url))){ $id = urldecode2id($url); $cache->set($url,$id); }

DESCRIPTION

Overview

Mediasurface relies on retrieving a unique ID for almost every object lookup. This module aims to cache url->id lookups in memory. The module works with a linked list, which is significantly slower at lookups than a standard Perl hash. However, the linked list allows commonly used key-value pairs to be stored towards the 'fresh' end of the list, and seldomly used pairs to drift towards the 'stale' end, from where they will eventually be pushed into oblivion, should the cache reach its maximum size. Basically, it's a trade-off between size and speed - the module will perform best when you need to perform lots of lookups of a wide range of urls, but the majority of lookups are contained within a much smaller subset of urls. Be warned - this module will cause a *reduction* in performance if used for single lookups, or if lookups are non-repetitive.

Constructor

$cache = Db::Mediasurface::Cache->new(size=>1000);

This class method constructs a new cache. the size parameter can be used to set the maximum number of key-value pairs to be cached (defaults to 1000).

Methods

$cache->set($key1,$value1,$key2,$value2...)

Sets key-value pairs.

$id = $cache->get($key1);

Gets the value of a given key. Returns the value, or undef if the key doesn't exist.

$cache->unset($key1);

Delete the key-value pair specified by the given key.

AUTHOR

Nigel Wetters (nigel@wetters.net)

COPYRIGHT

Copyright (c) 2001, Nigel Wetters. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 105:

Unknown directive: =over4

Around line 107:

'=item' outside of any '=over'

Around line 115:

Unknown directive: =over4

Around line 117:

'=item' outside of any '=over'