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

For mod_perl users:

in your httpd.conf, put this directive:

PerlAddVar PROJECT_DOCUMENT_ROOT /path/to/your/project/root/

and in your startup.pl:

use Apache::Cache ();

See Apache::SharedMem for more details.

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

AUTHOR

Olivier Poitrey <rs@rhapsodyk.net>

LICENCE

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc. :

59 Temple Place, Suite 330, Boston, MA 02111-1307

COPYRIGHT

Copyright (C) 2001 - Fininfo http://www.fininfo.fr

PREREQUISITES

Apache::Cache needs Apache::SharedMem available from the CPAN.

SEE ALSO

Apache::SharedMem

HISTORY

$Log: Cache.pm,v $ Revision 1.15 2001/08/29 07:45:32 rs add mod_perl specifique documentation

Revision 1.14 2001/08/28 13:22:46 rs major bugfix: _check_keys method wasn't clean keys correctly

Revision 1.13 2001/08/28 08:42:38 rs set method wasn't unlock on exit !

Revision 1.12 2001/08/17 13:26:36 rs some minor pod modifications

Revision 1.11 2001/08/17 13:20:45 rs - fix major bug in "get" method: on first timeout, status was set to "delete" method's status (often SUCCESS) instead of EXPIRED - add some sections to pod documentation