【问题标题】:Does `Age` have to be used when using `Cache-Control: max-age`?使用`Cache-Control: max-age`时是否必须使用`Age`?
【发布时间】:2022-01-22 17:08:20
【问题描述】:

引用Cache-Control:

max-age

max-age=N 响应指令指示响应在生成响应后 N 秒之前保持新鲜。

Cache-Control: max-age=604800

表示缓存可以存储此响应并在其新鲜时将其重用于后续请求。

请注意,max-age 不是自收到响应以来经过的时间,而是自在源服务器上生成响应以来经过的时间。 因此,如果响应所采用路径上的其他缓存将其存储 100 秒(使用 Age 响应标头字段表示),则浏览器缓存将从其新鲜度生命周期中扣除 100 秒。 [强调]

Cache-Control: max-age=604800
Age: 100

如果在使用Cache-Control: max-age时没有使用Age,浏览器能否知道缓存何时过期?如果可以,怎么做?

【问题讨论】:

    标签: http caching http-headers cache-control response-headers


    【解决方案1】:

    RFC 7234 解释了缓存如何estimate the age of a response message

    是的,如果可用,则使用 Age 标头:

    术语"age_value" 表示Age 标头字段的值 (第 5.1 节),以适合算术运算的形式;要么 0,如果不可用。

    还添加了响应延迟:

    response_delay = response_time - request_time;
    corrected_age_value = age_value + response_delay;
    

    如果不存在Age 标头,缓存可能会近似为:

    apparent_age = max(0, response_time - date_value);

    然后缓存使用两者中最大的一个:

    corrected_initial_age = max(apparent_age, corrected_age_value);
    

    【讨论】:

      猜你喜欢
      • 2012-06-30
      • 1970-01-01
      • 2020-08-11
      • 2014-07-31
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      相关资源
      最近更新 更多