1

I have been struggling with this question for several days.

What is the age of an object stored in a cache. In particular, I am wondering about Cloud Front. If I specify

Cache-Control: max-age=60, public

when I upload it at T = N, and then 10 minutes go by, is the official age of my entity 600 seconds? In other words, is the age of an entity NOW - T?

For example, if I push a file into S3 with an expiration date of 30 minutes, and then I do not push a new version of it for for 1 week, will Cloud Front re-validate (GET If-Modified-Since) that entity on every request? Or will it re-validate the entity every 30 minutes and set the age back to 0 after each re-validation?

I have looked here for a definition of age, but I am not quite sure what the answer is:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

jpayne
  • 111
  • 1
  • 8

1 Answers1

1

The max-age directive specifies the time, in seconds, after which the client should consider that the content at the given URL is invalid.

This means that if you have a max-age of 10 minutes, get the resource at instant t, then if you need the content at t + 9 minutes for instance, it will not be fetched. But its expiry date remains unchanged on the client side.

Which means at any instant after t + 10 minutes, the content will be fetched again, and its expiry time recalculated (since it may have changed in the meanwhile).

At least, that is how clients should operate.

max-age=0 is the equivalent of "always fetch that resource again".

fge
  • 119,121
  • 33
  • 254
  • 329
  • "Which means at any instant after t + 10 minutes, the content will be fetched again, and its expiry time recalculated (since it may have changed in the meanwhile)." But if it hasn't changed does it make sense to reset the expiry time again? – jpayne Jan 12 '13 at 19:17
  • The client doesn't care, it only cares about what the server tells it. If the server lies, the client is not at fault here ;) – fge Jan 12 '13 at 19:42
  • Note that I am not only talking about content expiration. Between two calls, the server configuration itself may have changed, but in any case, the client does not need to know. It trusts what the server tells it. – fge Jan 12 '13 at 19:43
  • In other words, if a piece of content is on a server, and remains unchanged for two weeks, and the server specifies max-age=1800 (30 minutes), the client will happily come back once every 30 minutes but no more often (assuming it's still in its cache). This is the behavior I want. It basically means, "If I change the content of that specific entity, it will be renewed in the client within 30 minutes." – jpayne Jan 12 '13 at 20:44
  • Well, not really: "the client will happily come back once every 30 minutes" <-- it won't, since it has no obligation to do so. It all depends on both the last time the client fetched a resource which it knew to be valid and when it needs it again. If it does not need it for the next 45 minutes, it has no reason to ask it again past 30, as per the specs. While you can do it, it is not required. The only criterion for a well-behaved client in this case is to check when it has last accessed the resource and when it knows that it has expired: if it has not expired, it will not fetch it again. – fge Jan 12 '13 at 20:51