简体   繁体   English

没有特定Symfony2 TWIG页面的缓存

[英]No cache for specific Symfony2 TWIG page

i want to disable a [twig] cache for an specific Action response on Symfony2? 我想为Symfony2上的特定Action响应禁用[twig]缓存?

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' ?? '缓存控制:无缓存,无存储,必须重新验证'?

You need to enable your auto_reload option on Twig_Environment . 你需要让auto_reload期权Twig_Environment You can read about it here: http://twig.sensiolabs.org/doc/api.html 你可以在这里阅读: 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: 为了尽量减少努力(并且不影响其他渲染操作),我建议您在要渲染Action响应时更改此选项:

$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(); 它会忽略在$twig->enableAutoReload();之后呈现的所有树枝模板的缓存$twig->enableAutoReload();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM