ModifyCacheLifetimeForPageEvent

New in version 12.0

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:

EXT:my_extension/Configuration/Services.yaml
services:
  # Place here the default dependency injection configuration

  MyVendor\MyExtension\Frontend\EventListener\MyEventListener:
    tags:
      - name: event.listener
        identifier: 'my-extension/cache-timeout'
Copied!

Read how to configure dependency injection in extensions.

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

API

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