eZ Platform uses Symfony HttpCache to manage content "view" cache with an expiration model. In addition it is extended (using FOSHttpCache) to add several advanced features. For content coming from the CMS the following is taken advantage of out of the box:
X-Location-Id
header, which both Symfony and Varnish Proxy are able to invalidate cache on (for details see cache purge document.)X-User-Hash
to allow pages to var by user rights (so not per unique user, that is better served by browser cache.)ezpublish: system: my_siteaccess: content: view_cache: true # Activates HttpCache for content ttl_cache: true # Activates expiration based HttpCache for content (very fast) default_ttl: 60 # Number of seconds an Http response is valid in cache (if ttl_cache is true) |
Sometimes you need your controller's cache to be invalidated at the same time as specific content changes (i.e. ESI sub-requests with render
twig helper, for a menu for instance). To be able to do that, you just need to add X-Location-Id
header to the response object:
use Symfony\Component\HttpFoundation\Response; // Inside a controller action // "Connects" the response to location #123 and sets a max age (TTL) of 1 hour. $response = new Response(); $response->headers->set('X-Location-Id', 123); $response->setSharedMaxAge(3600); |
If the content you're rendering depends on a user's permissions, then you should make the response Context-aware:
use Symfony\Component\HttpFoundation\Response; // Inside a controller action // Tells proxy configured to support this header to take the rights of a user (user hash) into account for the cache $response = new Response(); $response->setVary('X-User-Hash'); |