Cache::BaseCache(3pm) User Contributed Perl Documentation Cache::BaseCache(3pm)NAME
Cache::BaseCache -- abstract cache base class
DESCRIPTION
BaseCache provides functionality common to all instances of a cache. It differes from the CacheUtils package insofar as it is designed to
be used as superclass for cache implementations.
SYNOPSIS
Cache::BaseCache is to be used as a superclass for cache implementations. The most effective way to use BaseCache is to use the protected
_set_backend method, which will be used to retrieve the persistance mechanism. The subclass can then inherit the BaseCache's implentation
of get, set, etc. However, due to the difficulty inheriting static methods in Perl, the subclass will likely need to explicitly implement
Clear, Purge, and Size. Also, a factory pattern should be used to invoke the _complete_initialization routine after the object is
constructed.
package Cache::MyCache;
use vars qw( @ISA );
use Cache::BaseCache;
use Cache::MyBackend;
@ISA = qw( Cache::BaseCache );
sub new
{
my ( $self ) = _new( @_ );
$self->_complete_initialization( );
return $self;
}
sub _new
{
my ( $proto, $p_options_hash_ref ) = @_;
my $class = ref( $proto ) || $proto;
my $self = $class->SUPER::_new( $p_options_hash_ref );
$self->_set_backend( new Cache::MyBackend( ) );
return $self;
}
sub Clear
{
foreach my $namespace ( _Namespaces( ) )
{
_Get_Backend( )->delete_namespace( $namespace );
}
}
sub Purge
{
foreach my $namespace ( _Namespaces( ) )
{
_Get_Cache( $namespace )->purge( );
}
}
sub Size
{
my $size = 0;
foreach my $namespace ( _Namespaces( ) )
{
$size += _Get_Cache( $namespace )->size( );
}
return $size;
}
SEE ALSO
Cache::Cache, Cache::FileCache, Cache::MemoryCache
AUTHOR
Original author: DeWitt Clinton <dewitt@unto.net>
Last author: $Author: dclinton $
Copyright (C) 2001-2003 DeWitt Clinton
perl v5.12.4 2009-03-01 Cache::BaseCache(3pm)
Check Out this Related Man Page
HTML::Mason::Cache::BaseCache(3pm) User Contributed Perl Documentation HTML::Mason::Cache::BaseCache(3pm)NAME
HTML::Mason::Cache::BaseCache - Base cache object
DESCRIPTION
This is the base module for all cache implementations used in Mason. It provides a few additional methods on top of "Cache::BaseCache" in
Dewitt Clinton's "Cache::Cache" package.
An object of this class is returned from $m->cache.
METHODS
clear ()
Remove all values in the cache.
get (key, [%params])
Returns the value associated with key or undef if it is non-existent or expired. This is extended with the following optional
name/value parameters:
busy_lock => duration
If the value has expired, set its expiration time to the current time plus duration (instead of removing it from the cache) before
returning undef. This is used to prevent multiple processes from recomputing the same expensive value simultaneously. The duration
may be of any form acceptable to set.
expire_if => sub
If the value exists and has not expired, call sub with the cache object as a single parameter. If sub returns a true value, expire
the value.
get_object (key)
Returns the underlying "Cache::Object" object associated with key. The most useful methods on this object are
$co->get_created_at(); # when was object stored in cache
$co->get_accessed_at(); # when was object last accessed
$co->get_expires_at(); # when does object expire
expire (key)
Expires the value associated with key, if it exists. Differs from remove only in that the cache object is left around, e.g. for
retrieval by get_object.
remove (key)
Removes the cache object associated with key, if it exists.
set (key, data, [duration])
Associates data with key in the cache. duration indicates the time until the value should be erased. If duration is unspecified, the
value will never expire by time.
$expires_in may be a simple number of seconds, or a string of the form "[number] [unit]", e.g., "10 minutes". The valid units are s,
second, seconds, sec, m, minute, minutes, min, h, hour, hours, d, day, days, w, week, weeks, M, month, months, y, year, and years.
perl v5.14.2 2012-02-04 HTML::Mason::Cache::BaseCache(3pm)