Symfony2中缓存的内部路由

时间:2013-05-25 20:43:32

标签: symfony varnish

我在项目中使用内部路由并使用输出URL进行缓存(Varnish) 代码:

_internal:
    resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
    prefix:   /parts

和twig(base twig)包含代码:
{% render "my_controller:getHeaderAction" with {}, { "standalone" : true } %}
{% render "my_controller:getSidebarAction" with {}, { "standalone" : true } %}
{% render "my_controller:getFooterAction" with {}, { "standalone" : true } %}

这会生成如下网址:
/parts/my_controller%3AgetHeaderAction/none.html /parts/my_controller%3AgetSidebarAction/none.html /parts/my_controller%3AgetFooterAction/none.html

我试图为SidebarAction获取单独的Url,如:
/parts/prefix/my_controller%3AgetSidebarAction/none.html

但无法弄清楚如何做到这一点,因为内部路由会自动生成网址 对此有何解决方法?
谢谢你的时间。

1 个答案:

答案 0 :(得分:1)

您需要为my_controller:getSidebarAction手动定义路线规则,然后使用url标记进行渲染。

假设您正在使用Symfony 2.3,语法将是

{{ render_esi(url('latest_news', { 'max': 5 })) }}

注意我正在使用特殊的render_esi标记,这是在Symfony 2.2中添加的,以便为Varnish等反向代理添加更好的ESI支持。

此处有更多信息http://symfony.com/doc/current/book/http_cache.html#using-esi-in-symfony2