Apache-Cache
view release on metacpan or search on metacpan
keys.
Additionnally, you can implement a cache with Apache::Cache in your
module without the risk of namespace clash because Apache::Cache is
enclosed in the constructor's package's caller (see the
Apache::SharedMem manpage for more details).
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 the Apache::SharedMem manpage for more details.
METHODS
new (cachename=> 'cachename', default_expires_in=> '1 second', max_keys=> 50, max_size=> 1_000)
Constuct a new Apache::Cache's instance.
* "default_expires_in" optional, date
The default data expiration time for objects place in the cache.
Integers is interpreted in seconds, constant EXPIRES_NOW make data
expire imédiately and constant EXPIRES_NEVER make the data never
expire. The timeout can also be in a human readable format, see the
Time::ParseDate manpage for this format specification.
Defaults to constant EXPIRES_NEVER if not explicitly set.
* "max_keys" optional, integer
If you set more than "max_keys" keys, olders are automatically
removed. Usefull to control the cache's grow. NOTE: if you know the
exact length of your keys, use this option to control the cache size
instead of the "max_size" option.
Defaults to no max_keys
* "max_size" optional, integer
no yet implemented
* "cachename" optional, string
The namespace associated with this cache.
Defaults to "Default" if not explicitly set.
* "default_lock_timeout" optional, integer
Number of second(s) to wait for locks used each time manipulating
data in the shared memory.
Defaults to not waiting. This means a get() - for expample - on a
temporary locked key - certainely by another process - will return a
FAILED status.
Additionnaly, all Apache::SharedMem parameters are also customizable.
See the Apache::SharedMem manpage.
set (identifier => data, [timeout])
$cache->set(mykey=>'the data to cache', '15 minutes');
if($cache->status & FAILURE)
{
warn("can't save data to cache: $cache->error");
}
Store an item in the cache.
* "identifier" required, string
A string uniquely identifying the data.
* "data" required, scalar or reference to any perl data type, except
CODE and GLOB
The data to store in the cache.
* "timeout" optional, date
The data expiration time for objects place in the cache. Integers is
interpreted in seconds, constant EXPIRES_NOW make data expire
imédiately and constant EXPIRES_NEVER make the data never expire.
The timeout can also be in a human readable format, see the
Time::ParseDate manpage for this format specification.
On failure this method return "undef()" and set status to FAILURE, see
status() method below
status : FAILURE SUCCESS
get (identifier)
my $value = $cache->get('Key');
if($cache->status & (EXPIRED | FAILURE)) # if status is EXPIRED or FAILURE
{
$value = 'fresh value';
}
Fetch the data specified. If data where never set, or if data have
expired, this method return "undef" and status is set to EXPIRED.
* "identifier" required, string
A string uniquely identifying the data.
status : FAILURE SUCCESS EXPIRED
delete (identifier)
Delete the data associated with the identifier from the cache.
* "identifier" required, string
( run in 1.591 second using v1.01-cache-2.11-cpan-39bf76dae61 )