NAME
XML::Template::Cache::File - Document caching to files module.
SYNOPSIS
use XML::Template::Cache::File;
my $cache = XML::Template::Cache::File->new (%config)
|| die XML::Template::Cache::File->error;
my $document = XML::Template::Document->new ();
$cache->put ($docname, $document);
$document = $cache->get ($docname);
DESCRIPTION
This modules provides XML template caching to files. A given number of parsed (i.e., code has been generated) XML templates are stored in files in a speficied directory. When the directory is full, putting a document in the file cache causes the oldest (access time) entry to be deleted. The configuration variable $CACHE_DIR_SLOTS in XML::Template::Config sets the default size of the file cache directory.
If file caching is turned on, in the initialization of XML::Template::Process, a file cache object is placed in the load and put chain of responsiblity lists after the normal cache object. Hence, every load and put operation on a document will result in the file cache being queried right after the normal cache.
CONSTRUCTOR
A constructor method new is provided by XML::Template::Base. A list of named configuration parameters may be passed to the constructor. The constructor returns a reference to a new cache object or undef if an error occurred. If undef is returned, you can use the method error to retrieve the error. For instance:
my $cache = XML::Template::Cache::File->new (%config)
|| die XML::Template::Cache->error;
The following named configuration parameters are supported by this module:
- CacheDir
-
The directory to store parsed XML templated in. This value will override the default value
$CACHE_DIRinXML::Template::Config. - CacheDirSlots
-
The number of files to keep in the cache directoryt. This value will override the default value
$CACHE_DIR_SLOTSinXML::Template::Config.
PRIVATE METHODS
_init
This method is the internal initialization function called from XML::Template::Base when a new cache object is created.
PUBLIC METHODS
load
my $document = $cache->load ($docname);
The load method, returns a document stored in the cache named by $docname. If no document is found, undef is returned.
put
my $document = XML::Template::Document->new (Code => $code);
$cache->put ($docname, $document);
The put method stores a document in the cache. If the cache is full, the oldest accessed document is replaced. The first parameter is the name of the document. The second parameter is the document to store.
AUTHOR
Jonathan Waxman jowaxman@bbl.med.upenn.edu
COPYRIGHT
Copyright (c) 2002 Jonathan A. Waxman All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.