cache invalidation上,HTTP规范说:



我试图通过使用位置 header 来使缓存中的条目无效,但似乎无法正常工作。这是我的用例:

  • 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)的响应包含一个位置 header ,其中包含在请求(1)和(3)中使用的URI。我认为这应该会使folder/folder.34/contents的缓存条目无效,但是根据HttpWebResponse.IsFromCache属性,(3)中的响应似乎还是来自缓存。

    我在位置 header 中尝试了多种URI格式,包括:
  • Location: ../../../folders/folder.34/contents(以及其他各种“../”计数)
  • Location: folders/folder.34/contents
  • Location: /folders/folder.34/contents
  • Location: http://myhostname/folders/folder.34/contents

  • 但是仍然(3)似乎总是来自缓存。我在这里做错了什么?

    最佳答案

    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
    

    要有正确的行为。

    09-27 21:35