I’m trying to use the varnish caching with symfony2.
Setup is Varnish -> NGNIX -> php-fpm
My Code:
public function indexAction($city_url)
{
$response = new Response();
$response->setETag('foobar123fo');
if ($response->isNotModified($this->getRequest())) {
// return the 304 Response immediately
return $response;
}
$data = array('randA'=> rand() );
$response = $this->render('Foo:Event:index.html.twig', $data);
$response->setCache(array(
'public' => true,
));
$response->setETag('foobar123fo');
$response->setSharedMaxAge(10);
return $response;
This works as intended – I get cache hits, but the debug toolbar of Symfony is cached as well. Can anyone tell me, how to exclude the Toolbar from being cached? I´d like to see, that when serving the cached results, there are indeed no SQL-Querys for example.
Thanks a lot!
If page is fully cached on Varnish, request doesn’t even hit your web server. Not only there’s no SQL queries made but Symfony isn’t called at all.
Debug toolbar is part of the page and that’s why it’s cached. Again… Symfony is only called with the first request.
Read HTTP Cache chapter in the official docs again. There are two articles recommended in it which are also worth reading: