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¶
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\Attribute\AsEventListener;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Frontend\Event\ModifyCacheLifetimeForPageEvent;
#[AsEventListener(
identifier: 'my-extension/cache-timeout'
)]
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);
}
}
}
New in version 13.0: The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener
has been
introduced to tag a PHP class as an event listener. Alternatively, or if you
need to be compatible with older TYPO3 versions, you can also register an
event listener via the Configuration/Services.yaml
file. Switch to
an older version of this page for an example or have a look at the section
Implementing an event listener in your extension.
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)¶
- Parameters
$cacheLifetime (
int
) -- the cacheLifetime
- getCacheLifetime()¶
- Return type
int
- getPageId()¶
- Return type
int
- getPageRecord()¶
- Return type
array
- getRenderingInstructions()¶
- Return type
array
- getContext()¶
- Return type
TYPO3\CMS\Core\Context\Context