<?php
namespace App\Event;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class RequestListener {
public function onKernelResponse(ResponseEvent $event) {
if (!$event->isMainRequest()) {
// Don't do anything if it's not the master request
return;
}
$response = $event->getResponse();
$secondsToCache = 0;
$ts = gmdate("D, d M Y H:i:s", time() + $secondsToCache) . " GMT";
// Set multiple headers simultaneously
$response->headers->add([
'Expires' => $ts,
'Pragma' => 'cache',
'Cache-Control' => 'max-age='. $secondsToCache,
]);
}
}