ShouldUseCachedPageDataIfAvailableEvent

New in version 12.0

The PSR-14 event \TYPO3\CMS\Frontend\Event\ShouldUseCachedPageDataIfAvailableEvent 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.

Example

EXT:my_extension/Classes/Frontend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Frontend\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\Event\ShouldUseCachedPageDataIfAvailableEvent;

#[AsEventListener(
    identifier: 'my-extension/avoid-cache-loading',
)]
final readonly class MyEventListener
{
    public function __invoke(ShouldUseCachedPageDataIfAvailableEvent $event): void
    {
        if (!($event->getRequest()->getServerParams()['X-SolR-API'] ?? null)) {
            return;
        }
        $event->setShouldUseCachedPageData(false);
    }
}
Copied!

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, or if you need to be compatible with older TYPO3 versions, you can also register an event listener via the Configuration/Services.yaml file. Switch to an older version of this page for an example or have a look at the section Implementing an event listener in your extension.

API

class ShouldUseCachedPageDataIfAvailableEvent
Fully qualified name
\TYPO3\CMS\Frontend\Event\TYPO3\CMS\Frontend\Event

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

Does not have any effect if caching is disabled, or if there is no cached version of a page.

getController ( )
Returns
TYPO3CMSFrontendControllerTypoScriptFrontendController
getRequest ( )
Returns
PsrHttpMessageServerRequestInterface
shouldUseCachedPageData ( )
Returns
bool
setShouldUseCachedPageData ( bool $shouldUseCachedPageData)
param $shouldUseCachedPageData

the shouldUseCachedPageData