【问题标题】:Symfony2 response - Clear cache headers on back buttonSymfony2 响应 - 清除后退按钮上的缓存标头
【发布时间】:2013-03-21 00:28:48
【问题描述】:

按下后退按钮时我在清除缓存时遇到问题。

我的头信息说我是从缓存中加载的:

Status Code:200 OK (from cache)

我的回复设置为:

$response = new Response;
$response->expire();
$response->headers->addCacheControlDirective('must-revalidate', true);
$response->headers->addCacheControlDirective('allow_reload', true);

我做错了什么?文档方法似乎都不起作用...

【问题讨论】:

    标签: caching symfony response symfony-2.1 cache-control


    【解决方案1】:

    听取this article 的建议并设置列出的 Cache-Control 指令对我有用 - 通过按返回按钮向服务器发送请求。

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

    【讨论】:

    • 太棒了!非常感谢加蒂斯尔!像魅力一样工作!
    • 这是救命稻草。 FWIW,它与 Silex 配合得很好,并且使用 Symfony2 的 HTTP 组件。
    猜你喜欢
    • 2011-11-30
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    相关资源
    最近更新 更多