i have controller action rendered in twig with
{{ render_esi(controller('mywebsitebundle:element:header')) }}
the action looks 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 reload browser, "mytime"
changes everytime.
how can use setshardemaxage()
, twig renderd after maxage expired?
in symfony2 there's few things need in order activate esi caching.
1) in app/config/config.yml
make sure activated esi, fragments path.
framework: esi: { enabled: true } fragments: { path: /_proxy }
2) wrap kernel appcache object
// web/app.php $kernel = new appcache($kernel);
3) set appcache configuration
// app/appcache.php use symfony\bundle\frameworkbundle\httpcache\httpcache; class appcache extends httpcache { protected function getoptions() { return array( 'debug' => false, 'default_ttl' => 0, 'private_headers' => array('authorization', 'cookie'), 'allow_reload' => false, 'allow_revalidate' => false, 'stale_while_revalidate' => 2, 'stale_if_error' => 60, ); } }
about issue if caching response , problem it's reloading every time refresh page. make sure configuration allow_reload
property set false.
you can read more here: http://symfony.com/doc/current/book/http_cache.html
Comments
Post a Comment