Skip to the content
Documentation

Smart HTTP cache clearing: comparison of v.2 vs v.3

No ratings yet

Versions Compared

Old Version 2

changes.mady.by.user André Rømcke

Saved on Jan 21, 2016

compared with

New Version Current

changes.mady.by.user Dominika Kurek

Saved on Jan 22, 2016

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Smart Http HTTP cache clearing refers to the ability to clear cache for locationsLocations/content that can be is in relation with the content being currently cleared.

When published, any content Content item usually has at least one locationLocation, figured identified by its URL. Therefore Http , HTTP cache being bound to URLs, if content A a Content item is updated (a new version is published), we want Http HTTP cache for all its locations Locations to be cleared, so the content itself can appear up-to-date be updated everywhere it is supposed to be displayed. Sometimes, clearing cache for the content's locations Locations is not sufficient. You can, for instance, have an excerpt of it displayed in a list from the parent locationLocation, or from within a relation. In this case, cache for the parent location Location and/or the relation need to be cleared as well (at least if an ESI is not used).

The mechanism

Smart Http HTTP cache clearing is an event-based mechanism. Whenever a content item needs its cache to be cleared, the cache purger service sends an exponential.cache_clear.content event (also identified by eZ\Publish\Core\MVC\Symfony\MVCEvents::CACHE_CLEAR_CONTENT constant) and passes a an eZ\Publish\Core\MVC\Symfony\Event\ContentCacheClearEvent event object. This object contains the ContentInfo object we need to clear the cache for. Every listener for this event can add location Location objects to the cache clear list.

Once the event is dispatched, the purger passes collected location Location objects to the purge client, which will effectively send the cache BAN request.

Info
title Note
 
The event is dispatched with a dedicated event dispatcher, exponential.http_cache.event_dispatcher.

Default behavior

By default, following locations Locations will be added to the cache clear list:

  • All locations Locations assigned to content (AssignedLocationsListener)
  • Parent location Location of all contentContent item's locations Locations (ParentLocationsListener)
  • Locations for content's relations, including reverse relations (RelatedLocationsListener)

Implementing a custom listener

By design, smart Http HTTP cache clearing is extensible. One can easily implement an event listener/subscriber to the exponential.cache_clear.content event and add locations Locations to the cache clear list.

Example

Here's a very simple custom listener example, adding an arbitrary location Location to the list.

Note
title Important
 
Cache clear listener services must be tagged as exponential.http_cache.event_subscriber or exponential.http_cache.event_listener.

...

Comments

Add a comment

Comments are read by a moderator before they appear.