In my routing.yml
file I have the following definition according to the doc here :
webservice_resources:
path: /webservice/resources
defaults:
_controller: FooBarCogsBaseBundle:Resources:getResourcesByTags
maxAge: 3600
shareMaxAge: 3600
But the response headers indicate that these settings are ignored:
Cache-Control: private
I am expecting to see something more along the lines of this:
Cache-Control: public,max-age=3600,s-maxage=3600
Why would Symfony2 ignore the cache defaults?
What you are doing is based purely around static templates.
example in the symfony2 docs (you are not using a template, you are rendering a dynamic page it appears though):
acme_privacy:
path: /privacy
defaults:
_controller: FrameworkBundle:Template:template
template: 'static/privacy.html.twig'
maxAge: 86400
sharedAge: 86400
What you want is something like this (from 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);
Or per that same documentation:
If you need to set cache headers for many different controller actions, you might want to look into the FOSHttpCacheBundle.
Which is located at http://foshttpcachebundle.readthedocs.org/en/latest/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.