2010-11-19 82 views
3

在PHP中,默認情況下不會發送與緩存相關的頭文件。從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得到緩存?

回答

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

它可以導致example.com/index.php獲得緩存在某些情況下?

它不應該,但是有很多實現(特別是在移動設備/移動代理上),在這方面表現不正確。

還有很多關於緩存的不良信息 - 當從服務器發送時,'Pragma:no-cache'爲meaningless

以防止緩存:

header("Cache-Control: no-store, no-cache, must-revalidate"); 

當一切都失敗了 - check the manual