ModifyCacheLifetimeForPageEvent
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
The following listener limits the cache lifetime to 30 seconds in development context:
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\Core\Core\Environment;
use TYPO3\CMS\Frontend\Event\ModifyCacheLifetimeForPageEvent;
#[AsEventListener(
identifier: 'my-extension/cache-timeout',
)]
final readonly 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);
}
}
}