2013-03-21 26 views
3

cache invalidation,HTTP規範說:如何使位置標題使HTTP緩存無效?

一些HTTP方法必須引起緩存無效的實體。這可以是Request-URI引用的實體,也可以是Location或Content-Location標頭(如果存在)。

我試圖通過無效使用位置頭在我的緩存中的項目,但它似乎沒有奏效。這是我的用例:

  1. 15:13:23.9988 | GET | folders/folder.34/contents - 200 (OK)
  2. 15:13:24.1318 | PUT | folders/folder.34/contents/test.docx - 201 (Created)
  3. 15:13:24.1548 | GET | folders/folder.34/contents - 200 (OK) (cached)

的響應(2)包含一個位置標頭中的URI的請求(1)和使用(3 )。我相信這應該會使文件夾/文件夾34 /內容的緩存項無效,但根據HttpWebResponse.IsFromCache屬性,(3)中的響應看起來好像來自緩存。

我試圖在位置頭衆多URI格式,包括:

  • Location: ../../../folders/folder.34/contents(和其他各種 '../' 計數)
  • Location: folders/folder.34/contents
  • Location: /folders/folder.34/contents
  • Location: http://myhostname/folders/folder.34/contents

但仍然(3)似乎總是來自緩存。我在這裏做錯了什麼?

回答

4

HTTPBis更清晰:

http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-22#section-6

Because unsafe request methods (Section 4.2.1 of [Part2]) such as 
PUT, POST or DELETE have the potential for changing state on the 
origin server, intervening caches can use them to keep their contents 
up-to-date. 

A cache MUST invalidate the effective Request URI (Section 5.5 of 
[Part1]) as well as the URI(s) in the Location and Content-Location 
response header fields (if present) when a non-error response to a 
request with an unsafe method is received. 

因此,如果這是不是你看到的行爲,我的假設只會是你使用的是特定的HTTP客戶端不有正確的行爲。

我特別期待:

Location: /folders/folder.34/contents 

有正確的行爲。

+0

WinInet緩存(例如IE,.NET)不會顯示正確的行爲是否合理? – ladenedge 2013-04-15 03:12:49

+0

@ladenedge:當然;)HTTP是相當廣泛的,任何客戶端都會有一些錯誤。另外,我想你自己也證明了這一點。問題是:你錯誤地認爲你的軟件堆棧是無誤的,忽略了你自己的邏輯? ;) – Evert 2013-04-15 07:24:22

+0

它似乎很基本,但(啜泣)。無論如何,感謝你的幫助! – ladenedge 2013-04-15 08:19:50