在我的routing.yml
文件中,根据the doc here我有以下定义:
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会忽略缓存默认值?
答案 0 :(得分:0)
您正在做的事情完全基于静态模板。
在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.