NAME

Apache::Cache - Cache data accessible between Apache childrens

SYNOPSIS

use Apache::Cache qw(:all);

my $cache = new Apache::Cache(cachename=>"dbcache", default_expires_in=>"5 minutes");

my $value = get_data('value_45');
$cache->set('value_45'=>$value);
print STDERR "can't save data in the cache" if($cache->status eq FAILURE);

1 minute past

my $value = $cache->get('value_45');
# $value equal 'data'

10 minutes past

my $value = $cache->get('value_45');
# $value equal 'undef()'
if($cache->status eq EXPIRED)
{
    # update value
    $cache->lock(LOCK_EX); # optional
    $value = get_data('value_45');
    $cache->set('value_45' => $value);
    $cache->unlock;
}
elsif($cache->status eq FAILURE)
{
    # don't use cache, cache maybe busy by another child
    $value = get_data('value_45');
}

DESCRIPTION

This module allows you to cache data easily through shared memory. Whithin the framework of an apache/mod_perl use, this cache is accessible from any child process. The data validity is managed in the Cache::Cache model, but as well based on time than on size or number of keys.

USAGE

under construction

METHODS

new (cachename=> 'cachename', default_expires_in=> '1 second', max_keys=> 50, max_size=> 1_000)

set (key => value, [timeout])

$cache->set(mykey=>'the data to cache', '15 minutes'); if($cache->status eq FAILURE) { warn("can't save data to cache: $cache->error"); }

key (required): key to set

value (required): value to set

timeout (optional): can be on of EXPIRES_NOW, EXPIRES_NEVER (need import of :expires tag), or a time string like "10 minutes", "May 5 2010 01:30:00"... (see Time::ParseDate).

On failure this method return undef() and place status method to FAILURE.

status : FAILURE SUCCESS