ModifyCacheLifetimeForPageEvent¶
New in version 12.0
This event serves as a successor for the
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['get_cache_timeout']
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'
Copied!
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);
}
}
}
Copied!
API¶
- class \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 int $cacheLifetime
-
the cacheLifetime
- getCacheLifetime ( ) ¶
-
- returntype
-
int
- getPageId ( ) ¶
-
- returntype
-
int
- getPageRecord ( ) ¶
-
- returntype
-
array
- getRenderingInstructions ( ) ¶
-
- returntype
-
array
- getContext ( ) ¶
-
- returntype
-
TYPO3\CMS\Core\Context\Context