View caching

This part of the 4.x documentation is for eZ Publish 4.0, only reference section is common for all eZ Publish 4.x versions as well as eZ Publish 5.x "LegacyStack", please select the version you are using for the most up to date documentation!

Caching is a widely used technique supposing that frequently used information is retained in a temporary storage area for rapid access. It is extremely effective when the original data is expensive (usually in terms of access time) to fetch or compute/generate relative to reading the cache. Once the data is stored in the cache, future use can be made by accessing the cached copy rather than re-fetching or re-computing the original data, so that the average access time is lower.

eZ Publish includes a powerful caching mechanism that allows to improve system performance. This chapter describes a fundamental part of the cache systems in eZ Publish, called content view caching ("view caching" for short). This mechanism only works for "view" and "pdf" views of the "content" module.

Node view cache

This subsection describes how the view caches are generated when the nodes are accessed.

Whenever eZ Publish is requested to output information about a node (either by a system URL or a virtual URL), it executes the program code that is associated with the "view" view of the "content" module. Upon completion, the view returns a result to the module, which in turn returns it to the rest of the system. eZ Publish automatically generates an array called "module_result" containing information about which module that was run, which view that was called, the output that was produced and so on.

The actual output of the view (i.e. the XHTML code generated using one of the node templates) is put to "$module_result.content" and is included in the pagelayout by accessing this template variable:

{$module_result.content}

When the pagelayout is rendered, the {$module_result.content} part will be replaced with the actual output. If view caching is enabled, the entire result of the module will be cached. This means that the contents of the "module_result" variable will be put into a cache file located in the "var/example/cache/content" directory (where "example" is usually the name of the siteaccess that is being used - it is set by the "VarDir" directive in "site.ini" or an override).

Please note that eZ Publish creates multiple view caches for the nodes based on roles and user preferences. This means that for example different users (who are logged in, with different permissions/preferences) will be served different caches while anonymous users and users with the same type of permissions/preferences will be served the same file. In other words, when view caching is on, the "view" view of the "content" module will only be run if the system is unable to locate a view-cached version of the result - otherwise a cached version will be inserted in the pagelayout. Please note that the pagelayout itself is not cached by default.

Another thing worth noticing is that the view caches are also depending on some other parameters. For example:

Example

Let's say that node 46 is the company about page and the custom template "aboutpage.tpl" overrides the default "node/view/full.tpl" template for this particular node.

Both the virtual URL "http://www.mysite.com/company/about" and the system URL "http://www.mysite.com/content/view/full/46" point to this page. When one of these URLs is requested, the system will execute the "view" view of the "content" module using "46" as the ID number of the node and "full" as the view mode. The resulting XHTML code containing the company about information will be generated using the "aboutpage.tpl" template. The output will be put to "$module_result.content" and then will be included in the page layout.

If view caching is enabled for the "full" view mode, the entire result of the module will be cached in a file. The cache files get long names like for example "46-122bc591bf62e87a4e9ddcb5ba352bc4.cache". Next time the company about page is being accessed, the system will not go through the burden of executing the "view" view of the "content" module (generating the result, etc.) but load the cache file instead.

The $node variable

In eZ Publish versions prior to 3.9, the "$node" variable might be present in the page layout when view caching is disabled. From 3.9, this variable is not available in the page layout, regardless of whether view caching is enabled or not. It is recommended to use $module_result for fetching the necessary information (for example, "$module_result.node_id" outputs the ID number of the node that is being viewed).

PDF cache

The following text explains how the view cache is generated when a PDF version of a site page (a content node) is being accessed. Note that the PDF export mechanism has been deprecated in eZ Publish 4.0 and will be removed in future releases.

Whenever eZ Publish is requested to generate a PDF version of a node, it executes the program code that is associated with the "pdf" view of the "content" module. Instead of inserting the output into the page layout via $module_result.content, the system will fetch the actual page content (i.e. the attributes of the object that is encapsulated by the specified node) using the "pdf.tpl" template and generate a PDF file using "execute_pdf.tpl". These default templates are located in the "templates/node/view" directory of the standard design.

If view caching is enabled for the "pdf" view, the resulting PDF file will be cached. This means that the system will save a copy of the actual PDF document into a cache file located in the "var/example/cache/content" directory (where "example" is usually the name of the siteaccess that is being accessed - it is controlled by the "VarDir" directive in "site.ini" or an override).

Example

If node 46 is the company about page, then accessing the URL "http://www.mysite.com/content/pdf/46" will lead to executing the "pdf" view of the "content" module. The system will generate a PDF version of the company about page and display it to the user.

If view caching is enabled for the "pdf" view, the resulting PDF document will be cached in a file, for example called "46-3579d18de31e99fc84d2d9a5f113c3be.cache". Please note that this file can be opened using a PDF reader (in some cases it would have to be renamed to .pdf).

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2013 eZ Systems AS (except where otherwise noted). All rights reserved.