ModifyCacheLifetimeForPageEvent
New in version 12.0
This event serves as a successor for the
$GLOBALS
hook.
This event allows to modify the lifetime of how long a rendered page of a frontend call should be stored in the "pages" cache.
Example
Register the listener:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\Frontend\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/cache-timeout'
Read how to configure dependency injection in extensions.
The following listener limits the cache lifetime to 30 seconds in development context:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Frontend\EventListener;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Frontend\Event\ModifyCacheLifetimeForPageEvent;
final class MyEventListener
{
public function __invoke(ModifyCacheLifetimeForPageEvent $event): void
{
// Only cache all pages for 30 seconds when in development context
if (Environment::getContext()->isDevelopment()) {
$event->setCacheLifetime(30);
}
}
}