src/EventListener/NoCacheListener.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  4. class NoCacheListener
  5. {
  6.     public function onKernelResponse(ResponseEvent $event): void
  7.     {
  8.         $route $event->getRequest()->attributes->get('_route');
  9.         if (!in_array($route, [
  10.             'frontend_auction_list',
  11.             'frontend_auction_box',
  12.             'frontend_server_date',
  13.         ])) {
  14.             return;
  15.         }
  16.         $response $event->getResponse();
  17.         $response->setMaxAge(0);
  18.         $response->headers->addCacheControlDirective('must-revalidate');
  19.         $response->headers->addCacheControlDirective('no-store');
  20.         $response->headers->addCacheControlDirective('no-cache');
  21.     }
  22. }