Symfony2忽略路由默认缓存控制


Symfony2 ignores routing defaults cache control

在我的routing.yml文件中,根据这里的文档,我有以下定义:

webservice_resources:
    path: /webservice/resources
    defaults:
        _controller: FooBarCogsBaseBundle:Resources:getResourcesByTags
        maxAge: 3600
        shareMaxAge: 3600

但是响应头表明这些设置被忽略:

Cache-Control: private

我希望看到更多类似这样的内容:

Cache-Control: public,max-age=3600,s-maxage=3600

为什么Symfony2会忽略缓存默认值?

你所做的完全是基于静态模板。

symfony2文档中的

示例(您没有使用模板,但您正在呈现动态页面):

acme_privacy:
    path: /privacy
    defaults:
        _controller:  FrameworkBundle:Template:template
        template:     'static/privacy.html.twig'
        maxAge:       86400
        sharedAge:    86400

你想要的是这样的东西(来自http://symfony.com/doc/current/book/http_cache.html):

)
use Symfony'Component'HttpFoundation'Response;
$response = new Response();
// mark the response as either public or private
$response->setPublic();
$response->setPrivate();
// set the private or shared max age
$response->setMaxAge(600);
$response->setSharedMaxAge(600);

或者根据相同的文档:

If you need to set cache headers for many different controller actions, you might want to look into the FOSHttpCacheBundle.

位于http://foshttpcachebundle.readthedocs.org/en/latest/