Skip to the content
Documentation

Configuring the view cache

No ratings yet

The view cache is configured in site.ini [ContentSettings], per siteaccess or for all of them in settings/override/site.ini.append.php.

Setting Shipped value Meaning
ViewCaching enabled Whether content views are cached
CachedViewModes full;sitemap;pdf The view modes that are cached, separated by ;
CachedViewPreferences[] empty Per view mode, the user preferences the result depends on
ViewCacheTweaks[] empty Per node (or global), changes to how the cache is kept
CacheDir content The directory of the cache files below the cache directory
ComplexDisplayViewModes sitemap View modes that show more than a node's children; they are expired as a whole
CacheThreshold 250 When more nodes than this are to be cleared at once, all view caches are expired instead

During development

With the view cache on, a changed node template shows only after the cache is cleared. On a development siteaccess, switch it off:

# settings/siteaccess/<siteaccess>/site.ini.append.php
[ContentSettings]
ViewCaching=disabled

Switch it on again before the site goes live: it is the cache most page views are served from. [TemplateSettings] DevelopmentMode=enabled makes the template engine check the modification time of templates against their compiled files; it does not affect the view cache.

Turning the cache off for one page

A template can set the lifetime of its view cache with the variable cache_ttl, in seconds. 0 stores no cache for the page; -1 keeps it until it is cleared.

{* at the start of the node template: this page is never cached *}
{set-block scope=global variable=cache_ttl}0{/set-block}

The same is possible in the settings, which saves rendering the template to find out: ViewCacheTweaks[<node ID>]=disabled.

ViewCacheTweaks

ViewCacheTweaks[<node ID>]=<setting>[;<setting>]; global as the key applies to every node (except disabled).

Setting Effect
disabled No view cache for the node
pr_user One cache per user, instead of per role combination
protocol Separate caches for http and https
ignore_userroles, ignore_userlimitedlist, ignore_discountlist, ignore_viewparameters, ignore_userpreferences, ignore_siteaccess_type Leave that part out of the cache key, so more visitors share a file
ignore_siteaccess_name Use the default siteaccess's cache path for every siteaccess
[ContentSettings]
ViewCacheTweaks[]
ViewCacheTweaks[59]=disabled
ViewCacheTweaks[global]=protocol

Roles

Users with different roles (and role limitations) get different cache files, so a node template may show a button only to editors. Users with the same roles share them. A part of a page that differs per user, such as a greeting with the user's name, must not be in a cached node template: put it in the page layout, or use pr_user for that node.

User preferences

User preferences are values saved per user with /user/preferences/set/<name>/<value> (the administration uses them for the windows of the full view and the number of items per page; the shop for the preferred currency). When the template of a cached view mode depends on a preference, list it for that view mode, with its default value after =, so that each value gets its own cache file:

[ContentSettings]
CachedViewPreferences[full]=user_preferred_currency=''

Several preferences are separated with ;. When the setting already has a value for the view mode, add yours at the end of that line instead of replacing it.

Related siteaccesses

When the view cache of a node is cleared, it is cleared for the siteaccesses of [SiteAccessSettings] RelatedSiteAccessList[] too, the siteaccesses that share the database. Without that list, AvailableSiteAccessList[] is used.

See the settings of [ContentSettings] for the other keys of the group.

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.