Table of Contents
Recite CMS uses an on-disk caching mechanism to achieve significant performance gains when rendering client web sites.
As a developer, you can control how the cache operates in many different situations. For example, when developing custom container rules, you specify options to control how caching works for the output of the container (as well as for the page on which the container resides).
This chapter tells you to manipulate the cache so you can leverage the speed of Recite CMS in your own code, as well as being able to ensure that up-to-date content is being displayed.
Several of the other Recite CMS developer guides (available at
Recite CMS Documentation Portal
)
refer back to this chapter.
In certain instances (such as when developing container rules), custom code
will be required to return options that define how caching should work. These
options are specified using the Application_Cache_Options
class.
This class is primarily used to specify the maximum cache lifetime of the content in question, as well as any tags (keywords) that should be stored with the cache item.
If you do not want the content in question to be cached at all, call the cancel()
method.
Example 8.1. Preventing caching of the content in question
<?php $options = new Application_Cache_Options(); $options->cancel(); ?>
You can specify the maximum amount of time (in seconds) content can be cached for using the
setMaxLifetime()
method. Recite CMS may decide to cache
the content in question only for a shorter amount of time, but never for longer.
You can set an unlimited maximum lifetime (that is, so it never expires) by
passing Application_Cache_Options::LIFETIME_UNLIMITED
Example 8.2. Specifying the maximum lifetime of a cache entry
<?php $options = new Application_Cache_Options(); $options->setMaxLifetime(86400); // 1 day (in seconds) ?>
You can associate any number of tags (keywords) with a cache entry by calling
the addTag()
method. This is an extremely useful feature
since it allows you to later clear the cache by the given keyword, resulting
in the content in question no longer being cached.
For example, if you have a list of items that has been cached (to improve user loading time), you might want to clear this cache if a new item is added to the list. You can do so by clearing the cache by the tags you add to the cache options.
Example 8.3. Adding tags to a cache entry
<?php $options = new Application_Cache_Options(); $options->addTag('my custom tag') ->addTag('another tag'); ?>