View caching (11403666)
The content view cache keeps the rendered result of a content page, so that the next request for the same page does not render its node templates again. It is the cache behind most page views of an Exponential site, and it is on by default. It is one of several cache layers: the template-block cache ({cache-block}), the HTTP cache, the static cache and, under Exponential Velocity, its response cache sit around it (see Caches).
What is cached
When a node is viewed (by its URL alias or by /content/view/full/<node ID>), the content/view view renders the node template and returns the result to the page layout as $module_result.content. With view caching on, the whole module result is stored in a cache file below the cache directory of the siteaccess (var/<site>/cache/content/, site.ini [ContentSettings] CacheDir), and the next request reads it from there. The page layout around it is rendered on every request (it has its own {cache-block} caches).
Only the view modes in CachedViewModes are cached, by default full and sitemap (and pdf for the content/pdf view).
One cache file per variation
A node has several cache files, one for each combination of what can change the result:
- the view mode, the language, the siteaccess and the layout (/layout/set/print and others);
- the view parameters of the address (/(offset)/20);
- the user's roles and their limitations, and the shop's discount groups: users with the same roles share files, so templates may show different things to different roles;
- the user preferences listed in CachedViewPreferences[] for the view mode.
A cache file has a name like 46-122bc591bf62e87a4e9ddcb5ba352bc4.cache: the node ID and a hash of the rest.
Example: node 46 is the "About" page, shown with the template aboutpage.tpl. The first request for /company/about renders it and stores the result; the following requests by visitors with the same roles read it from the cache file, until the page or something related to it is published again.
The $node variable
The page layout does not get $node, whether the view cache is on or not: a cached result does not have it. Use $module_result there: $module_result.node_id, $module_result.content_info and $module_result.path.
The pages of this section
- Configuring the view cache: settings, turning it off for a page, roles, preferences.
- Clearing the view cache: what publishing clears, and clearing by hand.
- Smart view cache cleaning: rules for which other pages a publication clears.
- Pre-generation of view cache: building the cache when content is published.
History
Before the 3.9 release the page layout could see $node when the view cache was off. The PDF export, which the pdf view mode caches, still exists (Setup > PDF export, see PDF export).
In this section
- Configuring the view cache Configuring the view cache: ViewCaching, CachedViewModes, cache_ttl, ViewCacheTweaks, roles, user preferences and related siteaccesses.
- Clearing the view cache Clearing the view cache: what publishing clears, the administration menu, Setup > Caches and ezcontentcache.php.
- Smart view cache cleaning Smart view cache cleaning in viewcache.ini: rules per class, clear methods, MaxParents, ObjectFilter and AdditionalObjectIDs.
- Pre-generation of view cache Generating the view cache on publishing: PreViewCache, PreCacheSiteaccessArray and PreviewCacheUsers.
Contributors
- Svitlana Shatokhina
- Geir Arne Waaler
- Graham Brookins Updated Maintainer
Comments
Add a comment