ModifyCacheLifetimeForPageEvent¶
New in version 12.0
This event serves as a successor for the
$GLOBALS
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 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);
}
}
}
New in version 13.0
The PHP attribute \TYPO3\
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/
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 ModifyCacheLifetimeForPageEvent ¶
-
- Fully qualified name
-
\TYPO3\
CMS\ Frontend\ Event\ Modify Cache Lifetime For Page Event
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