NAME
Babble::Cache - Global caching infrastructure for Babble
DESCRIPTION
This module implements a global cache, a hash that is used to store stuff in; and a set of methods to update, query or otherwise manipulate the cache. Including loading and saving it, of course.
METHODS
Babble::Cache provides the following methods:
- cache_load ($fn)
-
Loads the file specified in $fn, if exists. The format of the database can vary. By default, it is valid perl code, dumped out with Data::Dumper, but it can be anything that the Babble::Cache::q sub-modules support.
- cache_frob ($category, $id, $data [, $keys])
-
Frobnicate stuff in the cache. This is a quite complex method, which does a few interesting things. First, it looks up if an entry named $id exists under the $category in the cache. If it does, all the keys listed in the $keys arrayref will be copied over from the cache. If the cache does not have the key yet, it will be updated.
If the entry is not found in the cache, the keys listed in $keys will be stored in it.
If $keys is not defined, all keys of $data will be used.
- cache_update ($category, $id, $data, $key)
-
Update the cache with the values of $data when its $key key is defined. Otherwise, return the contents of the appropriate entry of the cache.
- cache_get ($category, $id, $key)
-
Retrieve the value of the $key element in the $id key in the $category category of the cache.
- cache_dump ($fn)
-
Save the cache to the file specified in $fn.
VARIABLES
- $Babble::Cache::cache_format
-
Determines the format of the cache. Values can be Dumper (Data::Dumper will be used to dump the database, and require to restore it), or Storable (Storable will be used to dump and retrieve the data).
Defaults to Dumper, because that is easier to edit by hand, if needed.
STORAGE FORMATS
Storage formats are implemented by Babble::Cache sub-modules. A storage module needs to have two methods (both must be callble in an OO fashion):
- cache_load
-
Takes two arguments: the filename to read from (already verified that it exists), and a reference to a hashref, where the loaded data must be stored.
- cache_dump
-
Also takes two arguments: the filename to dump the cache to, and a reference to a hashref, containing the data to store.
AUTHOR
Gergely Nagy, algernon@bonehunter.rulez.org
Bugs should be reported at http://bugs.bonehunter.rulez.org/babble.
SEE ALSO
Babble(3pm), Babble::Cache::Dumper(3pm), Babble::Cache::Storable(3pm)