Message-ID: <451022634.4002.1485856260037.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_4001_1721456852.1485856260036" ------=_Part_4001_1721456852.1485856260036 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Smart HTTP cache clearin= g refers to the ability to clear cache for Locations/content that = is in relation with the content being currently cleared.
When published, any Content item usually has at least one Location, iden= tified by its URL. Therefore, HTTP cache being bound to URLs, if a Content = item is updated (a new version is published), we want HTTP cache for all it= s Locations to be cleared, so the content itself can be updated everywhere = it is supposed to be displayed. Sometimes, clearing cache for the content's= Locations is not sufficient. You can, for instance, have an excerpt of it = displayed in a list from the parent Location, or from within a relation. In= this case, cache for the parent Location and/or the relation need to be cl= eared as well (at least if an ESI is not used).
Smart HTTP cache clearing is an event-based mechanism. =
Whenever a content item needs its cache cleared, the cache purger service s=
ends an ezpublish.cache_clear.content
event (also identified b=
y eZ\Publish\Core\MVC\Symfony\MVCEvents::CACHE_CLEAR_CONTENT
c=
onstant) and passes an eZ\Publish\Core\MVC\Symfony\Event\ContentCache=
ClearEvent
event object. This object contains the ContentInfo object=
we need to clear the cache for. Every listener for this event can add Loca=
tion objects to the cache clear list.
Once the event is dispatched, the purger passes collected Location objec=
ts to the purge client, which will effectively send the cache BAN request.
Note
ezpublish.http_cache.event_dispatcher
.
By default, following Locations will be added to the cache clear list:= p>
AssignedLocationsListener)
ParentLocationsL=
istener
)R=
elatedLocationsListener
)By design, smart HTTP cache clearing is extensible. One can easily imple=
ment an event listener/subscriber to the ezpublish.cache_clear.conten=
t
event and add Locations to the cache clear list.
Here's a very simple custom listener example, adding an arbitrary Locati= on to the list.
Important
ezpublish.http_cache.event_subscriber
or=20
ezpublish.http_cache.event_listener
.
namespace Acme\AcmeTestBundle\EventListener; use eZ\Publish\API\Repository\LocationService; use eZ\Publish\Core\MVC\Symfony\Event\ContentCacheClearEvent; use eZ\Publish\Core\MVC\Symfony\MVCEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class ArbitraryLocationsListener implements EventSubscriberInterface { /** * @var LocationService */ private $locationService; public function __construct( LocationService $locationService ) { $this->locationService =3D $locationService; } public static function getSubscribedEvents() { return [MVCEvents::CACHE_CLEAR_CONTENT =3D> ['onContentCacheClea= r', 100]]; } public function onContentCacheClear( ContentCacheClearEvent $event ) { // $contentInfo is the ContentInfo object for the content being cle= ared. // You can extract information from it (e.g. ContentType from its c= ontentTypeId), using appropriate Repository services. $contentInfo =3D $event->getContentInfo(); // Adding arbitrary locations to the cache clear list. $event->addLocationToClear( $this->locationService->loadLo= cation( 123 ) ); $event->addLocationToClear( $this->locationService->loadLo= cation( 456 ) ); } }=20
parameters: acme.cache_clear.arbitrary_locations_listener.class: Acme\AcmeTestBundl= e\EventListener\ArbitraryLocationsListener services: acme.cache_clear.arbitrary_locations_listener: class: %acme.cache_clear.arbitrary_locations_listener.class% arguments: [@ezpublish.api.service.location] tags: - { name: ezpublish.http_cache.event_subscriber }=20