ShouldUseCachedPageDataIfAvailableEvent

New in version 12.0: This event was introduced.

This event allows TYPO3 extensions to register event listeners to modify if a page should be read from cache (if it has been created in store already), or if it should be re-built completely ignoring the cache entry for the request.

This event can be used to avoid loading from the cache when indexing via CLI happens from an external source, or if the cache should be ignored when logged in from a certain IP address.

API

class TYPO3\CMS\Frontend\Event\ShouldUseCachedPageDataIfAvailableEvent

Event to allow listeners to disable the loading of cached page data when a page is requested.

Does not have any effect if "no_cache" is activated, or if there is no cached version of a page.

getController()
Return type

TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController

getRequest()
Return type

Psr\Http\Message\ServerRequestInterface

shouldUseCachedPageData()
Return type

bool

setShouldUseCachedPageData(bool $shouldUseCachedPageData)
Parameters
  • $shouldUseCachedPageData (bool) -- the shouldUseCachedPageData

Example

Registration of the event in your extensions' Services.yaml:

my_extension/Configuration/Services.yaml
MyVendor\MyExtension\Frontend\MyEventListener:
  tags:
    - name: event.listener
      identifier: 'my-package/avoid-cache-loading'

The corresponding event listener class:

my_extension/Classes/Frontend/MyEventListener.php
use TYPO3\CMS\Frontend\Event\ShouldUseCachedPageDataIfAvailableEvent;

final class MyEventListener {

    public function __invoke(ShouldUseCachedPageDataIfAvailableEvent $event): void
    {
        if (!($event->getRequest()->getServerParams()['X-SolR-API'] ?? null)) {
            return;
        }
        $event->setShouldUseCachedPageData(false);
    }
}