AfterCacheableContentIsGeneratedEvent

New in version 12.0: This event together with AfterCachedPageIsPersistedEvent has been introduced to serve as a direct replacement for the removed hooks:

  • $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-cached']

  • $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-all']

  • $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['usePageCache']

The 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

Registration of the AfterCacheableContentIsGeneratedEvent in your extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
Vendor\MyExtension\Frontend\MyEventListener:
  tags:
    - name: event.listener
      identifier: 'my-extension/content-modifier'

The corresponding event listener class:

EXT:my_extension/Classes/Frontend/MyEventListener.php
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;

final 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);
    }
}

API

class TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent

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

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()
Return type

Psr\Http\Message\ServerRequestInterface

getController()
Return type

TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController

isCachingEnabled()
Return type

bool

disableCaching()
enableCaching()
getCacheIdentifier()
Return type

string