简体   繁体   中英

Does `Age` have to be used when using `Cache-Control: max-age`?

Quote from Cache-Control :

max-age

The max-age=N response directive indicates that the response remains fresh until N seconds after the response is generated.

 Cache-Control: max-age=604800

Indicates that caches can store this response and reuse it for subsequent requests while it's fresh.

Note that max-age is not the elapsed time since the response was received, but instead the elapsed time since the response was generated on the origin server. So if the other cache(s) on the path the response takes store it for 100 seconds (indicated using the Age response header field), the browser cache would deduct 100 seconds from its freshness lifetime. [emphasis added]

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

If Age isn't used when using Cache-Control: max-age , can browsers know when the cache is outdated? If they can, how?

RFC 7234 explains how a cache can estimate the age of a response message .

Yes, the Age header is used, if available:

The term "age_value" denotes the value of the Age header field (Section 5.1), in a form appropriate for arithmetic operation; or 0, if not available.

A response delay is also added to it:

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

If no Age header is present, a cache may approximate it with:

apparent_age = max(0, response_time - date_value);

The cache then uses the largest of the two:

     corrected_initial_age = max(apparent_age, corrected_age_value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM