I have a Controller whose Action is rendered in twig with
{{ render_esi(controller('MyWebsiteBundle:Element:header')) }}
The Action itself looks like this:
/**
* @return Response
*/
public function headerAction()
{
$currentLocale = $this->getCurrentLocale();
$response = $this->render('MyWebsiteBundle:Element:header.html.twig', array(
'currentLocale' => $currentLocale,
'myTime' => time()
));
$response->setPublic();
$response->setSharedMaxAge(3600);
return $response;
}
When I reload my Browser, the "myTime"
changes everytime.
How can I use setShardeMaxAge()
, so that the Twig is only renderd after the MaxAge is expired?
In Symfony2 there's a few things you need to do in order to activate esi caching.
1) In
app/config/config.yml
make sure you activated esi, with a fragments path.2) Wrap the kernel with the AppCache object
3) Set up the AppCache configuration
About your issue if it is caching your response and the only problem is that it's reloading every time you refresh the page. make sure the configuration
allow_reload
property is set to false.You can read more about it here: http://symfony.com/doc/current/book/http_cache.html