2012-05-02 130 views
1

在研究各種搜索引擎和網站本身#2採用的緩存策略,我不禁注意到在響應報頭的細微差別:瞭解緩存策略

谷歌搜索

Cache-Control: private, max-age=0 
Expires: -1 

雅虎搜索

Cache-Control: private 
Connection: Keep-Alive 
Keep-Alive: timeout=60, max=100 

搜索#1

Cache-Control: private 

必須有通過設置背後的一些合乎邏輯的解釋。有人可以照顧解釋差異,以便我們每個人都可以學習和獲益嗎?

回答

1

RFC2616 HTTP/1.1 Header Field Definitions, 14.9.1 What is Cacheable

private 
    Indicates that all or part of the response message is intended for a single 
    user and MUST NOT be cached by a shared cache. This allows an origin server 
    to state that the specified parts of the response are intended for only one 
    user and are not a valid response for requests by other users. A private 
    (non-shared) cache MAY cache the response. 

max-age=0意味着它可以被高速緩存到0秒。值爲零意味着不應執行緩存。

Expires=-1當存在max-age時應該忽略,-1是無效日期,應該在過去被解析爲一個值(意味着已經過期)。

RFC2616 HTTP/1.1 Header Field Definitions, 14.21 Expires

Note: if a response includes a Cache-Control field with the max-age directive 
     (see section 14.9.3), that directive overrides the Expires field 

HTTP/1.1 clients and caches MUST treat other invalid date formats, especially 
including the value "0", as in the past (i.e., "already expired"). 

persistent connectionsConnection: Keep-AliveKeep-Alive: timeout=60, max=100配置設置。除非另有說明,否則使用HTTP/1.1的所有連接都是持久性的,但這些標頭會更改實際的超時值,而不是使用瀏覽器默認值(其變化很大)。

+0

很好的答案。爲了使它完成,你能解釋爲什麼max-age = 0爲Google設置,而Yahoo和Stackoverflow不設置它?如果未設置max-age,則緩存如何運行? –

+0

Yahoo(se.search.yahoo.com)向我發送'private,max-age = 0,no-cache'。我不知道爲什麼StackOverflow沒有指定max-age,它目前允許瀏覽器緩存結果頁面。在Meta上詢問! – sisve