在PHP中,默认情况下不会发送与缓存相关的标头。
HTTP/1.1 200 OK
Date: Fri, 19 Nov 2010 11:02:16 GMT
Server: Apache/2.2.15 (Win32) PHP/5.2.9-2
X-Powered-By: PHP/5.2.9-2
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 26
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
现在,因为默认情况下它没有说缓存,是否会导致在某些情况下缓存example.com/index.php?
答案 0 :(得分:4)
是的,如果服务器端没有设置任何规则,浏览器通常会默认缓存某些文件(通常是图像和css)(参见browser cache)。
您可以设置缓存控制标头来控制它,或使用以下命令完全禁用它:
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
请参阅header中的示例#2,并阅读下面的注释。
答案 1 :(得分:4)
是。一般情况下,every successful response may be cached除非有constrains:
除非受到缓存控制(section 14.9)指令的特别约束,否则缓存系统可能总是将成功的响应(请参阅section 13.8)存储为缓存条目,如果是,则可以返回它而不进行验证新鲜的,并且可以在成功验证后返回它。
答案 2 :(得分:1)
是否会导致例如在某些情况下缓存example.com/index.php?
不应该,但是有很多实现(特别是在移动设备/移动代理上),在这方面表现不正确。
还有很多关于缓存的错误信息 - 从服务器发送时,'Pragma:no-cache'是meaningless。
防止缓存:
header("Cache-Control: no-store, no-cache, must-revalidate");
当其他所有方法都失败时 - check the manual