Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

symfony 3.4 cache control

<?php

namespace AppBundleListener;

use SymfonyComponentHttpKernelEventFilterResponseEvent;

class ResponseListener
{
    public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();

        $controller = $event->getRequest()->attributes->get('_controller');
        $requiredAssetAction = "AppBundleControllerWebsiteAssetsController::assetAction";

        if ($controller == $requiredAssetAction) {
            $response->headers->addCacheControlDirective('max-age', 900);
            $response->headers->addCacheControlDirective('s-maxage', 900);
            $response->headers->addCacheControlDirective('must-revalidate', true);
            $response->headers->addCacheControlDirective('public', true);
            $response->headers->removeCacheControlDirective('private');

        }

        $event->setResponse($response);
    }

}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #symfony #cache #control
ADD COMMENT
Topic
Name
8+3 =