Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Cache-block

The cache-block function in detail: keys, expiry (default 7200 seconds), ignore_content_expiry, subtree_expiry, what invalidates a block, safe keys for menus and user-dependent parts, and the mistakes that show one…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/templates/cache-block.md

On this page

Cache-block

This page is for designers who make expensive parts of a template cheap. A {cache-block} stores the output of its body and reuses it until its keys change or it expires. Implementation: lib/eztemplate/classes/eztemplatecachefunction.php and eztemplatecacheblock.php.

Contents

  1. Syntax and parameters
  2. Keys
  3. Expiry
  4. Safe patterns
  5. Mistakes
  6. Settings and clearing

Syntax and parameters

{cache-block keys=array( $module_result.uri, $current_user.role_id_list|implode( ',' ) ) expiry=3600}
    ...
{/cache-block}
ParameterMeaning
keysa value or array; each different combination gets its own cached copy
expirylifetime in seconds; default 7200 (DEFAULT_TTL); 0 means no time limit
ignore_content_expirykeep the copy when content is published (by default a publish expires cache-blocks)
subtree_expiryexpire when content below the given node (id or path) is published, instead of on every publish

Without keys, the block's position in the template is the only key: one copy for every page and visitor.

Keys

Every value that changes the output must be in the keys:

The block showsAdd to keys
a menu marking the current page$module_result.uri or the current node id
items depending on permissions$current_user.role_id_list|implode( ',' ) and $current_user.limited_assignment_value_list|implode( ',' )
the visitor's name or basket$current_user.contentobject_id (or do not cache it)
language-dependent textnothing extra when each language is its own siteaccess: the siteaccess name is part of every block's cache path

subtree_expiry also implies ignore_content_expiry: such a block expires only for publishes below its node. The simple design keys its whole frame by URI, basket state and user id; the admin pagelayout builds a user hash from role and limitation lists.

Expiry

  • Default: two hours, and on every content publish.
  • A footer that never changes with content: ignore_content_expiry and a long expiry.
  • A menu of a section: subtree_expiry with the section's root node, so publishing elsewhere keeps it.

Safe patterns

{* a top menu: same for everyone with the same roles on the same page *}
{cache-block keys=array( $module_result.uri, $current_user.role_id_list|implode( ',' ) ) subtree_expiry=2}
    {include uri='design:pagelayout/menu.tpl'}
{/cache-block}
{* a footer: same everywhere, changes rarely *}
{cache-block ignore_content_expiry expiry=86400}
    {include uri='design:pagelayout/footer.tpl'}
{/cache-block}

Mistakes

  • User data without the user in the keys: one visitor's name shown to others.
  • csp_nonce() inside a block: the stored nonce is wrong for every later request, and the script is blocked.
  • A fetch inside the block whose result is used outside it: on a cache hit, the fetch does not run.
  • Keys with many distinct values (full query strings, timestamps): one file per value, and no reuse. Cast or reduce them (the admin pagelayout casts its section filter to a number for this reason).
  • Nested cache-blocks: work, but make invalidation hard to reason about; avoid them.

Settings and clearing

  • site.ini [TemplateSettings] TemplateCache=enabled turns cache-blocks on (disabled: never used).
  • DelayedCacheBlockCleanup (default disabled) keeps expired subtree blocks on disk for a cronjob to remove.
  • Clear: php bin/php/ezcache.php --clear-id=template-block.

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.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x