AfterCacheableContentIsGeneratedEvent

The PSR-14 event \TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent can be used to decide if a page should be stored in cache.

It is executed right after all cacheable content is generated. It can also be used to manipulate the content before it is stored in TYPO3's page cache. In the Core, the event is used in EXT:indexed_search to index cacheable content.

The AfterCacheableContentIsGeneratedEvent contains the information if a generated page is able to store in cache via the $event->isCachingEnabled() method. This can be used to differentiate between the previous hooks contentPostProc-cached and contentPostProc-all. The later hook was called regardless of whether the cache was enabled or not.

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\AfterCacheableContentIsGeneratedEvent;

#[AsEventListener(
    identifier: 'my-extension/content-modifier',
)]
final readonly class MyEventListener
{
    public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
    {
        // Only do this when caching is enabled
        if (!$event->isCachingEnabled()) {
            return;
        }
        $event->getController()->content = str_replace(
            'foo',
            'bar',
            $event->getController()->content,
        );
    }
}
Copied!

New in version 13.0

API

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

Event that allows to enhance or change content (also depending on enabled caching).

Think of $this->isCachingEnabled() as the same as $TSFE->no_cache. Depending on disable or enabling caching, the cache is then not stored in the pageCache.

getRequest ( )
Returns
\Psr\Http\Message\ServerRequestInterface
getController ( )
Returns
\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
isCachingEnabled ( )
Returns
bool
disableCaching ( )
enableCaching ( )
getCacheIdentifier ( )
Returns
string