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: Shorten the cache lifetime in the development context 

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);
    }
  }
}
Copied!

API 

final class ModifyCacheLifetimeForPageEvent
Fully qualified name
\TYPO3\CMS\Frontend\Event\ModifyCacheLifetimeForPageEvent

Event to allow listeners to modify the amount of seconds that a generated frontend page should be cached in the "pages" cache when initially generated.

setCacheLifetime(int $cacheLifetime)
param $cacheLifetime

the cacheLifetime

getCacheLifetime()
Returns
int
getPageId()
Returns
int
getPageRecord()
Returns
array
getRenderingInstructions()
Returns
array
getContext()
Returns
\TYPO3\CMS\Core\Context\Context