With Symfony2 why are ESI tags inside cached responses ignored?

浪子不回头ぞ 提交于 2019-12-04 11:41:23
Jones03

It appears that ESI in Symfony2 doesnt work with the Latmodified/Etag cache validation structure that you used. See here: https://groups.google.com/forum/?fromgroups=#!topic/symfony2/V4BItzpLbOs

Similar question here: Edge Side Includes and validation cache in Symfony 2

I've been trying to do the same as you, but can only get ESI to work by using expiration cache.

Since 2.0.20/2.1.5 Symfony2 takes a fully qualified URL instead of a controller logical path, as per CVE-2012-6431. So, instead of your current ESI:

{% render 'PurchaseBundle:Basket:summary' with {}, { 'standalone': true } %}

You should create a route and then use the url method on twig:

{% render url('basket_summary') with {}, {'standalone': true} %}

Also note that today (March 1st) a new stable version of Symfony (2.2.0) has been released with major improvements on sub-requests management. With this new version, you can take two approaches (extracted from the master version of the HTTP Cache chapter in The Book):

{# you can use a controller reference #}
{{ render_esi(controller('...:news', { 'max': 5 })) }}

{# ... or a URL #}
{{ render_esi(url('latest_news', { 'max': 5 })) }}

The side notes on the current version of the linked chapter are worth reading as well, as they contain delicious pieces of information and nice tips that may help you finding the actual problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!