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

NAME

xppcache - How to make your own XPP Store and Expiry modules

XPP Caching

XPP makes use of a flexible caching system. Caching is split between two jobs: storing, and expiring. Likewise, content can be cached using any combination of Store and Expiry modules. Each cached entity is indexed by a name and group. This document will cover what you need to know to add your own Store and Expiry modules to XPP.

Store Modules

Store modules provide XPP with a way to store cache data. The way in which this data is stored is up to the module, and is fairly transparent to the XPP code wishing to cache the data. Here are the methods that need to be in every Store module for things to work:

REQUIRED METHODS

new ( $name, $group, \%instance_data, \$content, @args )

Returns an object that may be used to retrieve the content. $name and $group must be stored in the object as they represent a distinct cache entity. %instance_data is data that the caller requests the object store as instance data (and provide accessors to retrieve again). Common use of %instance_data might include the Apache request object. $content is is passed by reference and is the content to be stored.

If further arguments are required to implement a specific Store, they should be documented as required arguments following the content (in @args). For example, a File based store might provide the ability to choose the directory in which the content is stored - the directory name would be the singular argument in @args.

content ( )

Returns the $content passed to new (the content, not the reference).

is_expired ( )

Is called when the cache has expired, and should be cleaned up. For example, a File based store would remove the associated file by calling unlink.

Expiry Modules

REQUIRED METHODS

new ( $name, $group, \%instance_data, @args )

Returns an object that may be used to retrieve expiry information. $name and $group must be stored in the object as they represent a distinct cache entity. %instance_data is data that the caller requests the object store as instance data (and provide accessors to retrieve again). Common use of %instance_data might include the Apache request object.

Any arguments following %instance_data are Expiry specific, and should provide any information necessary to create a valid expiry. For example, the Duration expiry which expires a cache after a specific amount of time, expects a string representing the time interval (such as '15m' or '2d').

is_expired ( )

This method should return TRUE if the cache has expired at the current point in time, and FALSE if the cache is still valid.

SEE ALSO

Apache::XPP::Cache, Apache::XPP::Cache::Store, Apache::XPP::Cache::Expiry

AUTHORS

Greg Williams <greg@cnation.com>