简体   繁体   English

缓存控制不起作用

[英]cache control not working

I've jusy finished a login script and noticed that even after I log out that I can go back and view the protected page again. 我已经完成了一个登录脚本的jusy,并注意到即使注销后也可以返回并再次查看受保护的页面。 This really isn't an issue because the user can't do any damage but I do get loads of javascript errors that I don't like. 这确实不是问题,因为用户无法造成任何损害,但是我确实收到了很多我不喜欢的javascript错误。 I'd like to be able to totally prevent client side caching if at all possible. 我希望能够完全阻止客户端缓存。

I've tried the following but it isn't working as I can still go back and see a cached copy. 我尝试了以下操作,但由于我仍然可以返回并查看缓存的副本,因此无法正常工作。 Here is what I'm using so far. 这是我到目前为止使用的。

    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

Have you tried something a little more comprehensive? 您是否尝试过一些更全面的方法?

Expires: Sat, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache

Source: http://www.php.net/manual/en/function.session-cache-limiter.php 来源: http//www.php.net/manual/en/function.session-cache-limiter.php

I'm not sure if this will work for an entire page, but it's worth a shot. 我不确定这是否适用于整个页面,但是值得一试。

We serve up dynamic images that have the exact same file name, over and over. 我们不断提供具有完全相同文件名的动态图像。 Obviously caching these images would be bad, bad, bad (and completely break our app, really). 显然,缓存这些图像会很糟糕,很糟糕,很糟糕(实际上完全破坏了我们的应用程序)。

So, we send these three headers to the browser, and it has been working great to completely eliminate all caching of the images on all browsers: 因此,我们将这三个标头发送到浏览器,并且在完全消除所有浏览器上图像的所有缓存方面一直表现出色:

//Prevent the image from caching, so it is created fresh each time.
app.Response.AddHeader("pragma", "no-store,no-cache"); // //HTTP 1.0
app.Response.AddHeader("cache-control", "no-cache, no-store, must-revalidate, max-age=-1"); // HTTP 1.1
app.Response.AddHeader("expires", "Mon, 14 Jul 1789 12:30:00 GMT"); // Date in the past

Note: We tested LOTS of variations, but these were the three essential ingredients in the magic recipe to prevent client-side image caching. 注意:我们测试了很多变化版本,但这是防止客户端图像缓存的神奇配方中的三个基本要素。 You may have success using these for an entire page, but I have not tested that specific scenario. 您可能会在整个页面上成功使用它们,但是我尚未测试该特定方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM