缓存策略交互 — 最长使用期限和最长过期时间

来源:互联网 发布:正则表达式 手机号js码 编辑:程序博客网 时间:2024/06/05 17:00

To help ensure that the freshest content is returned to the client application, the interaction of client cache policy and server revalidation requirements always results in the most conservative cache policy. All the examples in this topic illustrate the cache policy for a resource that is cached on January 1 and expires on January 4.

In the following examples, the maximum staleness value (maxStale) is used in conjunction with a maximum age (maxAge):

  • If the cache policy sets maxAge = 5 days and does not specify a maxStale value, according to the maxAge value, the content is usable until January 6. However, according to the server’s revalidation requirements, the content expires on January 4. Because the content expiration date is more conservative (sooner), it takes precedence over the maxAge policy. Therefore, the content expires on January 4 and must be revalidated even though its maximum age has not been reached.

  • If the cache policy sets maxAge = 5 days and maxStale = 3 days, according to the maxAge value, the content is usable until January 6. According to the maxStale value, the content is usable until January 7. Therefore, the content gets revalidated on January 6.

  • If the cache policy sets maxAge = 5 days and maxStale = 1 day, according to the maxAge value, the content is usable until January 6. According to the maxStale value, the content is usable until January 5. Therefore, the content gets revalidated on January 5.

When the maximum age is less than the content expiration date, the more conservative caching behavior always prevails and the maximum staleness value has no effect. The following examples illustrate the effect of setting a maximum staleness (maxStale) value when the maximum age (maxAge) is reached before the content expires:

  • If the cache policy sets maxAge = 1 day and does not specify a value for maxStale value, the content is revalidated on January 2 even though it has not expired.

  • If the cache policy sets maxAge = 1 day and maxStale = 3 days, the content is revalidated on January 2 to enforce the more conservative policy setting.

  • If the cache policy sets maxAge = 1 day and maxStale = 1 day, the content is revalidated on January 2.


为了确保新的内容返回到客户端应用程序,在最保守的客户端缓存策略和服务器重新验证要求总是相互作用的结果。本主题中的所有示例说明是基于1月1日缓存,并于1月4日到期的资源的缓存策略。

在下面的例子中,最大的过期值(maxstale)采用的是与最大年龄结合(MAXAGE):

  • 如果缓存策略集MAXAGE = 5天不指定maxstale值,根据MAXAGE价值,内容可用到1月6日。然而,根据服务器的验证要求,内容在1月4日到期。因为内容截止日期比较保守(早),它将优先于MAXAGE政策。因此,该内容在1月4日到期,必须重新验证即使其最大年龄尚未达到。

  • 如果缓存策略集MAXAGE = 5天,maxstale = 3天,根据MAXAGE价值,内容可用到1月6日。根据maxstale价值,内容可用到1月7日。因此,内容在1月6日被重新验证。

  • 如果缓存策略集MAXAGE = 5天,maxstale = 1天,根据MAXAGE价值,内容可用到1月6日。根据maxstale价值,内容可用到1月5日。因此,内容在1月5日被重新验证。

当最大年龄小于内容到期日期,更保守的缓存行为被执行和最大失效期的值没有影响。下面的例子说明设置最大失效期的影响(maxstale)值时的最大年龄(MAXAGE)是内容到期之前达成:

  • 如果缓存策略集MAXAGE = 1天不指定maxstale值,内容是在1月2日被重新验证,即使它没有过期。

  • 如果缓存策略集MAXAGE = 1天,maxstale = 3天,内容是在1月2日执行更为保守的策略设置。

  • 如果缓存策略集MAXAGE = 1天,maxstale = 1天,内容是在1月2日执行更为保守的策略设置。

原创粉丝点击