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

Caching in applications

Cache an application's work correctly - which kernel caches exist, cache blocks for template output, caching computed data in PHP with eZClusterFileHandler and expiry, clearing on change, caches under Velocity's…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/creators/app-creators/caching-in-applications.md

On this page

Caching in applications

This page is for application creators who cache computed data and rendered output. Caching makes pages fast; a wrong key or a missing clear shows one user another user's data or keeps stale data forever.

Contents

  1. The kernel's caches
  2. Template output: cache blocks
  3. Computed data in PHP
  4. Clearing
  5. Under persistent workers

The kernel's caches

CacheClears onYour concern
Content view cachepublish of the node and related contentviews of content are cached per user's roles; your view module output is not
Template block cachepublish (by default), expirykeys and expiry of your blocks
Compiled templates, overrides, INItemplate and setting changesclear after deploys
Velocity response cacheits own rules and explicit clearsanonymous pages only

The full list with ids and tags: 10.6 Caches.

Template output: cache blocks

{cache-block keys=array( 'expdemo-stats', $current_user.contentobject_id ) expiry=300}
  {def $stats = fetch( 'expdemo', 'stats', hash() )} ... {undef $stats}
{/cache-block}

Data from your own tables does not trigger the publish clear: choose an expiry that matches how stale it may be, or add ignore_content_expiry and clear the template-block cache yourself when your data changes (Template functions, includes and cache blocks).

Computed data in PHP

Store expensive results through the kernel's cluster file handler, so they work on one server and on a cluster:

$file = eZClusterFileHandler::instance( eZSys::cacheDirectory() . '/expdemo/stats.cache' );
$stats = $file->processCache(
    function ( $path, $mtime ) {                                          // read a valid cache file
        return json_decode( (string)file_get_contents( $path ), true );
    },
    function ( $path ) {                                                  // generate when expired or missing
        $stats = expDemoStats::compute();
        return array( 'content' => $stats, 'binarydata' => json_encode( $stats ), 'scope' => 'expdemo-stats' );
    },
    300 );                                                                // $ttl: seconds from storing

processCache( $retrieveCallback, $generateCallback = null, $ttl = null, $expiry = null, $extraData = null ) is documented in kernel/classes/clusterfilehandlers/ezfsfilehandler.php: the retrieve callback gets the path and the mtime, the generate callback the path and returns content (returned to you) and binarydata (written to the file); while one process generates, others wait instead of generating the same data.

Clearing

  • Clear what you cached when its source changes: in the code that changes it, or in a workflow event or listener.
  • Give your cache a directory of its own so it can be removed alone.
  • An extension can add its cache to the cache list (site.ini [Cache] CacheItems[] and a [Cache_<id>] block, as the shipped [Cache_rest] does), so ezcache.php --clear-id=<id> and Setup > Caches can clear it, as the kernel's [Cache_*] blocks do.

Under persistent workers

Velocity keeps PHP processes between requests: a static variable or a singleton survives into the next request. Never keep user-specific data in static variables; reset per-request state, or key it by request. Process memory is not shared between workers, so it is not a shared cache either (Velocity persistent worker server).

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