wiki:Docs/Advanced/TemplateCache
Last modified 7 years ago Last modified on 08/11/06 17:29:08

WikiInclude(Includes/Header)?

Using a template cache

When using a template cache, patTemplate does not have to apply regular expressions to your template source for every request, but cache the result of the reader.

Using a template cache is extremely easy:

$tmpl = new patTemplate();
$tmpl->setRoot('templates');

$tmpl->useTemplateCache('File', array(
                                  'cacheFolder' => './tmplCache',
                                  'lifetime'    => 10,
                                  'filemode'    => 0644
                                )
                        );
$tmpl->readTemplatesFromInput('myTemplate.tmpl');
$tmpl->displayParsedTemplate();

The following caches are available:

  • File
  • MMCache
  • eAccelerator

Each of these caches has different options, please refer to the API documentation of the cache to learn about the supported parameters.

How caches work

When enabling a cache, patTemplate will store a serialized array containing all templates, that have been read from a file in the cache. The next time you call readTemplatesFromInput(), patTemplate will first check, whether there is a cached version instead of reading the template from the file and evaluating all enclosed tags.

The template cache will not cache the output of your pages.