4.3.4. Freshening Stored Responses upon Validation

3 阅读2分钟

4.3.4. Freshening Stored Responses upon Validation

rfc 7234 4.3.4. Freshening Stored Responses upon Validation

这一小节主要讲,当收到304 response时,如何利用它来刷新stored responses。

Freshening时机

 When a cache receives a 304 (Not Modified) response and already has
   one or more stored 200 (OK) responses for the same cache key, the
   cache needs to identify which of the stored responses are updated by
   this new response and then update the stored response(s) with the new
   information provided in the 304 response.

当cache收到304 response时,如果cache中有一个或者多个具有相同 cache key 的stored responses,cache需要选中(identify)其中一部分,然后利用 304 response中的信息更新来更新选中的部分。

返回304的情况

目前发现只有如下情况可能会返回304:

  • If-Modified-Since+GET/HEAD
  • If-None-Match+GET/HEAD

304 response携带信息

rfc 7232 4.1. 304 Not Modified

返回时的header/body规则参考4.1. 304 Not Modified

identified过程

进入并执行第一个满足的那一条

1.

If the new response contains a strong validator (see Section 2.1
      of [RFC7232]), then that strong validator identifies the selected
      representation for update.  All of the stored responses with the
      same strong validator are selected.  If none of the stored
      responses contain the same strong validator, then the cache MUST
      NOT use the new response to update any stored responses.
  • 这里的“strong validator”特指Etag
  • 对比方式:"with the same strong validator",估计指的是强匹配(TODO)
  • 如果new response contains a strong validator但是没有任何selected,则禁止(MUST NOT)进行update操作。TODO:rfc对这种情况的后续处理没 明确定义。

2.

 o  If the new response contains a weak validator and that validator
      corresponds to one of the cache's stored responses, then the most
      recent of those matching stored responses is selected for update.

这里的“weak validator”指的是:

  • weak Etag,例如:Etag: W/"123"
  • stored response中的Last-Modified

两种情况的“corresponds to”

3.

If the new response does not include any form of validator (such
      as in the case where a client generates an If-Modified-Since
      request from a source other than the Last-Modified response header
      field), and there is only one stored response, and that stored
      response also lacks a validator, then that stored response is
      selected for update.

TODO:如果上述3条都没进入,rfc没有定义后续该如何处理

update操作(MUST)

   o  delete any Warning header fields in the stored response with
      warn-code 1xx (see Section 5.5);

   o  retain any Warning header fields in the stored response with
      warn-code 2xx; and,

   o  use other header fields provided in the 304 (Not Modified)
      response to replace all instances of the corresponding header
      fields in the stored response.