Redirecting and preventing cache in Symfony2

后端 未结 2 1473
我寻月下人不归
我寻月下人不归 2020-12-31 22:02

I am doing this:

domain.com/route-name/?do-something=1

..which sets a cookie and then redirects to this using a 302 redirect:



        
2条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 22:15

    Try this on your response:

    $response->headers->addCacheControlDirective('no-cache', true);
    $response->headers->addCacheControlDirective('max-age', 0);
    $response->headers->addCacheControlDirective('must-revalidate', true);
    $response->headers->addCacheControlDirective('no-store', true);
    

    You can use annotations too:

    http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html

    And take a look at:

    Why both no-cache and no-store should be used in HTTP response?

提交回复
热议问题