Configuring the view cache

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!

The view caching mechanism is enabled by default. However, you probably want to turn it off during site development (otherwise any changes being made in your custom node templates will not be visible on the site until you clear the caches). This can be done by adding the following line under the "[ContentSettings]" section in the "site.ini.append.php" file of your siteaccess:

ViewCaching=disabled

Note that it is strongly recommended to re-enable the view caching when development has finished. This can be done by changing it from "disabled" to "enabled":

ViewCaching=enabled

The CachedViewModes setting located in the "[ContentSettings]" section of the "site.ini" configuration file (or an override) controls which view modes the caching will be enabled for. The default value of this setting defines that view cache should be stored for "full", "sitemap" view modes and for the "pdf" view:

CachedViewModes=full;sitemap;pdf

However, note that the "pdf" view of the content module is deprecated.

If you need to disable view caching for a specific page, add the following line in the beginning of the template that is used:

{set-block scope=root variable=cache_ttl}0{/set-block}

This will set the global variable "cache_ttl" to zero for the current template. The "cache_ttl" variable contains the TTL (Time To Live) value as seconds. A value of 0 means that the result should always be updated. Anyway, a cache file will be generated on the first access, but for content validation purposes only. This cache file will not be updated anymore, and will not be used to load content into the block, since the content (if cache_ttl is set to 0) will always be loaded dynamically. That means this cache block will always expire.

On the other hand, a value of -1 means that the view cache should never expire. A cache file will be generated on the first access, and it will be always used to load content to the block. No dynamic information will be fetched on this case, since the "time to live" of the cache block will be infinite.
See a usage example below:

{set-block scope=root variable=cache_ttl}-1{/set-block}

Roles

The cache files are different for dissimilar role combinations. This means that the templates can have conditions based on roles even when view caching is on.

User preferences

The following text describes handling of user preferences and the way the preferences of the current user are taken into account when generating content view cache.

For example, whenever the user performs the following actions using the administration interface:

...or sets any other user preference, the system executes the "preferences" view of the "user" module in order to save the selected value. The information about which preference has been changed is passed using view parameters:

.../user/preferences/set/<name_of_preference>/<value>

for example

http://my.com/myadmin/user/preferences/set/admin_left_menu_width/medium

After saving the selected value, the "preference" view of the "user" module will redirect the user back to the last accessed page.

If your templates of cached view modes have conditions based on user preferences, you should specify which preferences that are used together with the different view modes - this can be done using the CachedViewPreferences setting located under the "[ContentSettings]" section of the "site.ini.append.php" configuration file.

Example

Let's say that you are using prices in several currencies for your products and the "node/view/full.tpl" template is overridden for products in order to display prices in the user's preferred currency. If view caching is enabled for the "full" view mode, the system will store view cache files for the product view pages. If the cache is generated regardless of the preferred currency, when another preferred currency is chosen, the same product page that is being viewed will be returned (in other words, it will not change).

In order to avoid this, you need to specify the "user_preferred_currency" preference in the "CachedViewPreferences[]" array using "full" as an array key so that the cache will be stored for each possible preferred currency on your site. To do this, open the "site.ini.append.php" configuration file located in the "settings/siteaccess/example" directory (replace "example" with the actual name of the siteaccess) and edit it. If the "[ContentSettings]" section of the configuration file already contains something like

CachedViewPreferences[full]=<list_of_user_preferences>

then you will have to append a semicolon and "user_preferred_currency" at the end of the line, for example:

CachedViewPreferences[full]=admin_navigation_content=0;
admin_navigation_details=0;<...>;admin_bookmarkmenu=1;
admin_left_menu_width=13;user_preferred_currency=''

Note that this configuration line tends to be very long. It is simplified in the example above (a lot of settings were replaced with <...> in order to keep things short).

If the "[ContentSettings]" section does not contain a line that starts from "CachedViewPreferences[full]", create it:

CachedViewPreferences[full]=user_preferred_currency=''

Related siteaccesses

The RelatedSiteAccessList setting located under the "[SiteAccessSettings]" section of the "site.ini.append.php" configuration file controls which other siteaccesses the view cache should be cleared for when it is cleared for the current siteaccess. (This requires the VarDir configuration setting to be the same for all related siteaccesses.) If the RelatedSiteAccessList setting is not specified, the cache subsystem will use the AvailableSiteAccessList setting instead.

Note that the AvailableSiteDesignList setting located under the "[VersionView]" section of the "content.ini" configuration file is no longer (from eZ Publish 3.8) used by the cache system. In 3.7 and earlier versions, it could contain an array of designs that would be touched when the caches were cleared.

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