NAME

XML::Template::Cache - Document caching module for XML::Template.

SYNOPSIS

use XML::Template::Cache;

my $cache = XML::Template::Cache->new (%config)
  || die XML::Template::Cache->error;
my $document = XML::Template::Document->new ();
$cache->put ($docname, $document);
$document = $cache->get ($docname);

DESCRIPTION

This modules provides the basic document caching mechanism used by XML::Template. Parsed (i.e., code has been generated) documents are stored in a private array. When the array is full, putting a document in the cache causes the oldest (access time) entry to be replaced.

In the initialization of XML::Template::Process, a cache object is placed at the beginning of the load and put chains of responsiblity. Hence, every load and put operation on a document will result in the cache being queried first.

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->new (%config)
  || die XML::Template::Cache->error;

The following named configuration parameters are supported by this module:

CacheSlots

The size of the cache array. This value will override the default value $CACHE_SLOTS in XML::Template::Config. The default cache array size if 5.

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-2003 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.