dmitri
dmitri

Reputation: 469

No cache for specific Symfony2 TWIG page

i want to disable a [twig] cache for an specific Action response on Symfony2?

Is a solution to do this.

I'm not sure if I will add on response next header response will be not cached

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

Upvotes: 3

Views: 2308

Answers (1)

Michael Sivolobov
Michael Sivolobov

Reputation: 13240

You need to enable your auto_reload option on Twig_Environment. You can read about it here: http://twig.sensiolabs.org/doc/api.html

To make it with minimal efforts (and with no affect to other rendering operations) I recommend you to change this option at the moment when you want to render your Action response:

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

It will ignore cache for all twig templates that are rendered after $twig->enableAutoReload();

Upvotes: 2

Related Questions