Template caches
A template is cached in several ways at once, each with its own key, its own expiry and its own way to clear it. Knowing which cache holds an output is most of the work when "my change does not show". This page lists them in the order a request meets them.
Contents
- Overview
- Compiled templates
- The template override cache and the design base cache
- The content view cache
- The template-block cache (cache-block)
- The INI cache
- Clearing, and what a deploy clears
- Related pages
Overview
The caches the kernel knows are listed in eZCache::fetchList() (kernel/classes/ezcache.php); each has an id for
php bin/php/ezcache.php --clear-id=<id> and tags for --clear-tag=<tag>:
| Cache | id | Tags | Folder below var/<site>/cache/ | Switched on by |
|---|---|---|---|---|
| Compiled templates | template | template | template/ | [TemplateSettings] TemplateCompile |
| Template-block (cache-block) | template-block | template, content | template-block/ | [TemplateSettings] TemplateCache |
| Template override | template-override | template | override/ | always |
| Content view | content | content | [ContentSettings] CacheDir (content) | [ContentSettings] ViewCaching |
| Design base list | design_base | template | design base cache files | [DesignSettings] DesignLocationCache |
| INI | ini, global_ini | ini | ini/, and var/cache/ini | always |
| Translation | translation | i18n | always |
php bin/php/ezcache.php --list-ids and --list-tags print the full list of an installation, with the caches of
extensions. The template-related settings on the site siteaccess:
TemplateCompile: ezini( 'TemplateSettings', 'TemplateCompile' )
DevelopmentMode: ezini( 'TemplateSettings', 'DevelopmentMode' )
TemplateCache: ezini( 'TemplateSettings', 'TemplateCache' )
NodeTreeCaching: ezini( 'TemplateSettings', 'NodeTreeCaching' )
ViewCaching: ezini( 'ContentSettings', 'ViewCaching' )
CachedViewModes: ezini( 'ContentSettings', 'CachedViewModes' )Output:
TemplateCompile: enabled
DevelopmentMode: disabled
TemplateCache: enabled
NodeTreeCaching: disabled
ViewCaching: enabled
CachedViewModes: full;sitemap;pdf;googlesitemapCompiled templates
The PHP files of the template compiler, one per template, siteaccess and locale. A compiled
template is rebuilt when its own file is newer; an included template is only checked for a newer file with
DevelopmentMode=enabled. Clear with --clear-id=template.
The template override cache and the design base cache
The design resource keeps two lookups:
- the override cache (
override/): the match rules ofoverride.iniper template, built byeZTemplateDesignResource::createOverrideCache(). A new override rule or a new template file is not seen until it is cleared (--clear-id=template-override); a changed existing template is. - the design base cache: the ordered list of design folders of the siteaccess, written when
DesignLocationCache=enabled(eZTemplateDesignResource::allDesignBases()). Clear it (--clear-id=design_base) after adding a design to an extension or enabling an extension with a design.
The content view cache
content/view stores the whole $Result of a node view (HTML, content_info, the persistent variable, the list of
templates used) for the view modes in [ContentSettings] CachedViewModes (full;sitemap;pdf;googlesitemap on
a development installation). The cache file name is a hash of (eZNodeviewfunctions::generateViewCacheFile()):
- node ID, view mode, language, offset, layout;
- the user's role IDs, limited-assignment values and discount rules (each can be left out with a
ViewCacheTweaksvalue:ignore_userroles,ignore_userlimitedlist,ignore_discountlist); - the index file, the siteaccess (unless
ignore_siteaccess_name) and, for URI siteaccesses, the access type; - the view parameters (unless
ignore_viewparameters); - user preferences listed in
CachedViewPreferencesfor the view mode; - keys an extension adds through the
content/view/cachekeysevent filter.
It expires when content is published (the cache manager clears the node and the nodes related to it, by the rules of
viewcache.ini), when the global content-view-cache expiry timestamp moves, and when one of the templates in
template_list is newer than the cache file. A node template can shorten its life with {set-block scope=root variable=cache_ttl}0{/set-block} (as the cjw_newsletter templates do): $cache_ttl set to 0 stops caching of that
page, a positive value is
a lifetime in seconds. Clear with --clear-id=content.
The template-block cache (cache-block)
cache-block stores the output of a part of a template (lib/eztemplate/classes/eztemplatecachefunction.php,
eztemplatecacheblock.php). Not run on a development installation: rendering a cache-block writes a cache file, so this example is shown
without output:
cache-block keys=array( $node.node_id, $view_parameters.offset ) subtree_expiry=$node.node_id expiry=3600
foreach fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id, 'limit', 10 ) ) as $child
node_view_gui content_node=$child view='line'
/foreach
/cache-block| Parameter | Effect |
|---|---|
keys | values that make the cache differ; anything, arrays are walked |
expiry | lifetime in seconds; default 7200 (eZTemplateCacheFunction::DEFAULT_TTL); 0 means no time limit |
ignore_content_expiry | do not expire when any content is published |
subtree_expiry | a node ID, URL alias or content/view/full/<id>; the block expires when content below that node is published; implies ignore_content_expiry |
How the cache is found:
- The key always includes the placement of the tag (
eZTemplateCacheBlock::placementString(): start line and column, end line and column, template file) and the siteaccess name, plus thekeysvalue when given. Two cache-blocks never share a file, and moving a cache-block in its template makes a new file. - The file name is the md5 of that key, stored in
template-block/<a>/<b>/<c>/<md5>.cache, or below the subtree folder of the node forsubtree_expiry. - Without
ignore_content_expiry, every publish expires every such block: publishing sets thetemplate-block-cachetimestamp (eZContentObject::expireTemplateBlockCache()). The globalglobal-template-block-cachetimestamp, moved by clearing the cache, expires all blocks. - With
TemplateCache=disabledthe block's content is rendered every time, as if the tag were not there.
Things that follow:
- Anything that differs per visitor, per role or per request inside a block must be in
keys, or it is shown to the next visitor too.$current_user.contentobject_idin the keys makes one block per user. rand,currentdateand similar values freeze until the block expires.- A
definside a block is not run on a cache hit: variables the rest of the template needs must be defined outside.
The designer's guide is Cache block.
The INI cache
Settings files are cached as PHP in var/cache/ini (global_ini) and the site cache's ini folder. A change to an
.ini file of an extension or of settings/ is seen after --clear-tag=ini; the templates that read settings with
ezini() then get the new value.
Clearing, and what a deploy clears
php bin/php/ezcache.php --clear-id=template,template-override --allow-root-user
php bin/php/ezcache.php --clear-tag=template --allow-root-user
php bin/php/ezcache.php --clear-all --allow-root-user./console exp:velocity deploy (kernel/classes/expvelocitydeploy.php) clears, in this order: the template,
template-override, translation and design_base caches, then, after reloading PHP and restarting Velocity,
content, exphttpcache, ezjscore-packer (with --packer) and template-block. The order matters: a page
rendered with the old code between a clear and a reload would be cached again.
Which to clear after what:
| You changed | Clear |
|---|---|
| an existing template | nothing with DevelopmentMode=enabled; otherwise template, and content / template-block for cached output |
| a new template file or a new override rule | template-override (and template) |
| a design folder of an extension | design_base, template-override |
| a setting | ini tag |
| content | nothing: publishing expires the view cache and the template-block cache |
Related pages
- The template compiler
- Template compilation and cache
- Cache block
- Template resources and overrides
- Caching in applications
- ezcache
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.