I'm trying to get my Symfony2 application to cache a page using the expiration model but it doesn't see to be setting the s-maxage properly and the browser always returns s-maxage=0 regardless what value I set it to.
I'm currently using
public function indexAction()
{
$response = $this->render('HtgPageBundle:Default:fullPage.html.twig');
$response->setMaxAge(60);
$response->setSharedMaxAge(60);
return $response;
}
I've not set used $response->setPublic() as this is being done automatically using the setSharedMaxAge().
The response I'm getting from the browser is always
Cache-Control:max-age=60, public, s-maxage=0
X-Symfony-Cache:GET /page/privacy-policy: miss
But I was expecting:-
Cache-Control:max-age=60, public, s-maxage=60
X-Symfony-Cache:GET /page/privacy-policy: store
Digging into it I found that setSharedMaxAge is getting called twice, once when I'm calling it as above, and at this point it is setting the right value. Subsequently it's getting called again via the Symfony\Component\HttpFoundation\Response::setTtl() method but here it's setting the value to 0 but I'm not sure why it's doing it.
I'm using Symfony v2.4.4
Any suggestions
I've just fix it: https://github.com/sonata-project/SonataBlockBundle/commit/aa963aede9e505b1534e2c5471547f823512da10
So no need anymore to disable the listener.