在cache invalidation上,HTTP规范说:
某些HTTP方法必须导致缓存使实体无效。这可以是Request-URI引用的实体,也可以是Location或Content-Location头(如果存在)。
我正在尝试通过使用位置标头使我的缓存中的条目无效,但它似乎无法正常工作。这是我的用例:
15:13:23.9988 | GET | folders/folder.34/contents - 200 (OK)
15:13:24.1318 | PUT | folders/folder.34/contents/test.docx - 201 (Created)
15:13:24.1548 | GET | folders/folder.34/contents - 200 (OK) (cached)
(2)的响应包含位置标头,其中包含请求(1)和(3)中使用的URI。我认为这应该使 folders / folder.34 / contents 的缓存条目无效,但是根据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)似乎总是来自缓存。我在这里做错了什么?
答案 0 :(得分: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
拥有正确的行为。