<?php
namespace App\EventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class NoCacheListener
{
public function onKernelRequest(RequestEvent $event): void
{
$route = $event->getRequest()->attributes->get('_route');
// Add here your routes that should not be cached
$routeNames = [
'customer_show_cart',
];
if (!in_array($route, $routeNames)) {
return;
}
$response = $event->getResponse();
if(!$response){
return;
}
$response->setMaxAge(0);
$response->headers->addCacheControlDirective('must-revalidate');
$response->headers->addCacheControlDirective('no-store');
$response->headers->addCacheControlDirective('no-cache');
}
}