ch07: Caching
Last updated
Last updated
reduce redundant data transfers.
reduce network bottlenecks.
reduce demand on origin servers.
reduce distance delays.
Revalidate hit: HTTP 304 Not Modified response.
Revalidate miss: HTTP 200 OK.
Object deleted: HTTP 404 Not Found.
Hit rate: describes how many web transactions are kept off the outgoing network.
Byte hit rate: describes how many bytes are kept off the Internet.
Private caches and public caches.
Caches can also be built into hierarchy.
Receiving: Cache reads the arriving requests message from the network.
Parsing: Cache parses the message, extracting the URL and headers.
Lookup: Cache checks if a local copy is available and, if not, fetches a copy (and stores it locally).
Freshness check: Cache checks if cached copy is fresh enough and, if not, asks server for any updates.
Response creation: Cache makes a response message with the new headers and cached body.
Sending: Cache sends the response back to the client over the network.
Logging: Optionally, cache creates a log file entry describing the transaction.
Flow chart:
Document expiration and server revalidation.
HTTP lets an origin server attach an "expiration date" to each document, using special HTTP Cache-Control and Expires headers.
If revalidation shows the content has changed, the cache gets a new copy of the document, stores it in place of the old data, and sends the document to the client.
If revalidation shows the content has not changed, the cache gets a new headers, including a new expiration date, and updates the headers in the cache.
Two conditional headers used in cache revalidation:
If-Modified-Since:
If-None-Match:
A server can define how long a document can be cached before it expires. In decreasing order of priority, the server can:
Attach a Cache-Control: no-store header to the response.
Attach a Cache-Control: no-cache header to the response.
Attach a Cache-Control: must-revalidate header to the response.
Attach a Cache-Control: max-age header to the response.
Attach an Expires date header to the response.
Attach no expiration information, letting the cache determine tis own heuristic expiration date.
No-Store: forbids a cache from making a copy of the response.
No-Cache: a response can actually be stored in the local cache storage. It just cannot be served from the cache to the client without first revalidating the freshness with the origin server.
The Cache-Control: max-age header indicates the number of seconds since it came from the server for which a document can be considered fresh.
s-maxage applies only to shared caches.
Servers can request that caches either not cache a document or refresh on every access by setting the maximum aging to zero:
Deprecated
Use an absolute time.
LM-Factor algorithm: guess a fresh time.
Age:
Header
Description
Cache-Control: max-age
The max-age defines maximum age of the document(in seconds).
Expires
Specifies an absolute expiration date. If the expiration date is in the past, the document is no longer fresh.
Header
Description
If-Modified-Since: \
Perform the requested method if the document has been modified since the specified date. This is used in conjunction with the Last-Modified server response header, to fetch content only if the content has been modified from the cached version.
If-None-Match: \
Instead of matching on last-modified date, the server may provide special tags on the document that act like serial numbers. The If-None-Match header performs the requested method if the cached tags differ from the tags in the server's document.