To configure a response without a cache in the controller, you can do this:
$response = new Response(); $result = $this->renderView( 'AcmeDemoBundle:Default:index.html.twig', array('products' => $products, 'form' => $form->createView())); $response->headers->addCacheControlDirective('no-cache', true); $response->headers->addCacheControlDirective('max-age', 0); $response->headers->addCacheControlDirective('must-revalidate', true); $response->headers->addCacheControlDirective('no-store', true); $response->setContent($result); return $response;
But using annotations to ensure that each method has the same result, how can you do this?
I tried this, but keep saving the cache, and if I use the browser back button, the cache is saved:
class DefaultController extends Controller { public function indexAction() { $sessionCart = $this->get('demo'); $filters = $sessionCart->getFilters($this->getDoctrine()->getEntityManager()); $products = $this->getDoctrine()->getRepository('AcmeDemoBundle:Product')->search($filters); $form = $this->createForm(new FilterType, $filters); return array('products' => $products, 'form' => $form->createView()); }
If it is indicated that the documentation states:
@Cache(vary=["no-cache", "must-revalidate", "no-store"]...
gives a syntax error that does not expect "[", so I tried as above.
source share