No cache for specific TWIG Symfony2 page

I want to disable [twig] cache for a specific action on Symfony2?

This is the solution for that.

I am not sure if I add the response in the following header response, will not be cached

'Cache-Control: no-cache, no-store, must-revalidate' ??

+3


source to share


1 answer


You need to enable the parameter auto_reload

on Twig_Environment

. You can read about it here: http://twig.sensiolabs.org/doc/api.html

To do this with minimal effort (and without affecting other rendering operations), I recommend that you change this parameter at the moment you want to respond with Action:



$twig = $this->get('twig');
$twig->enableAutoReload();
$twig->render('AcmeDemoBundle:Test:index.html.twig', $parameters);

      

It will ignore the cache for all branch templates that appear after $twig->enableAutoReload();

+2


source







All Articles