Feature: #96879 - New PSR-14 event ModifyCacheLifetimeForPageEvent
See forge#96879
Description
A new PSR-14 event Modify
has been introduced.
This event serves as a successor for the
$GLOBALS
hook.
Impact
The new event allows to modify the lifetime how long a rendered page of a frontend call should be stored in the "pages" cache.
Common registration and usage for a listener:
services:
MyCompany\MyPackage\EventListener\ChangeCacheTimeout:
tags:
- name: event.listener
identifier: 'mycompany/mypackage/cache-timeout'
Copied!
<?php
namespace MyCompany\MyPackage\EventListener;
class ChangeCacheTimeout
{
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!