Suppose you’ve requested a webpage with a
Last-Modified date and no other caching headers:
HTTP/1.1 200 OK Last-Modified: Tue, 16 Dec 2014 06:00:00 GMT ...
The HTTP client will happily store this response in the cache indefinitely. But it won't serve it from the cache unless it’s still fresh at the time of request.
How do we decide whether it’s still fresh? There are three timestamps we’re interested in:
- Last requested at: Timestamp when we made the last request.
- Last modified at: What the
Last-Modifiedheader said on that response.
- Now: Timestamp at the time of the current request.
We use the time between last requested at and last modified at to estimate how frequently a document is edited. If a page was modified 5 minutes before the request, it’s assumed to be frequently modified. If it was last modified 5 years before the request, it’s assumed to be infrequently modified.
A page is fresh for 10% of that duration: 10% of 5 minutes is 30 seconds; 10% of 5 years is 6 months. A page is considered fresh until that 10% has elapsed since the document was last requested.