0

When i set Cache-Control: 'max-age=0' in request header,this request will revalidate its cache entry (eg. with the If-Not-Modified header) all the way to the origin server. If the reply is then 304 (Not Modified), the cached entity can be used.

When i set Cache-Control: 'max-age=20' in response header,It,s mean is whilein 20 s , Request at the same address will use the cache.

But if i set Cache-Control: 'max-age=20' in request header,It doesn't work as well as the former,So i want to know what will happen when i set max-age=xxx(xxx != 0) in request header?

planB
  • 1
  • 3
  • Does this answer your question? [Can a user agent set a max-age greater than zero in its request?](https://stackoverflow.com/questions/46339832/can-a-user-agent-set-a-max-age-greater-than-zero-in-its-request) – Joe Nov 20 '21 at 03:51

1 Answers1

0

The specification tells us:

The max-age request directive indicates that the client is unwilling to accept a response whose age is greater than the specified number of seconds.

So max-age=20 means that the cache shouldn't return a cached response older than 20 seconds.

The key difference here is that the client is choosing the desired freshness time of the resource, while in the usual case it's the server determining that.

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
  • Thank you for your answer. So if I set `Cache-Control: 'max-age=5'` in request headers and set `Cache-Control: 'max-age=20'` in response headers at the same time, it means that I can,t receive the cache after 5 seconds? – planB Nov 19 '21 at 13:41
  • But when I experimented with that, I found that I could still receive a cache of 20 seconds – planB Nov 19 '21 at 13:43
  • @planB: I'm not sure what you mean by "receive a cache". In any case, the request header applies to entries already in the cache. The cache headers in the response are unrelated, they will only apply to future requests. – Kevin Christopher Henry Nov 19 '21 at 14:24