Skip to content
All writing ‹ Part 06 of 18 · A Cache Is a Chain, Not a Box
Engineering · 3 min read

Cache Headers: Who Sets, Who Reads

Every cache header has a setter and a reader. Standard headers, Akamai debug headers, and custom headers that do nothing when no rule reads them.

Every cache header has a setter and a reader. If only one side is present, the header does nothing.

I used to look at a header’s name and value only. This time I learned to ask one more question: who reads it?

origin sets Cache-Control / ETag CDN reads and obeys CDN sets Age / X-Cache next layer and browser read CDN sets custom header only the layer witha written rule reads
Standard headers have a reader by default, but a custom header is read only where someone wrote a rule for it.

Standard Headers

HeaderWho setsWho readsExample
Cache-Controloriginevery cache layerpublic, max-age=3600
Expiresoriginold-style cachesan absolute time
Ageevery cache layernext cache layerage: 54
ETagorigincache, to compare versions"32b7140e..."
If-None-Matchcache, when it refreshesorigincarries the old ETag

CDN Own Headers (Akamai as the example, names differ by vendor)

HeaderPurpose
X-CacheThe result at the edge layer, for example TCP_HIT
X-Cache-RemoteThe result at the second layer (tiered cache)
Pragma: akamai-x-cache-onI add it to the request, and then Akamai returns X-Cache and X-Cache-Remote

Headers We Add Ourselves

HeaderWho addsWho reads
X-Cache-Bypass: yesAkamai adds it to every request sent to the originOnly the LB cache backends that have a written rule
x-use-proxy: 1Akamai adds it to requests with an html, css, or js extensionThe load balancer uses it to pick the proxy backend

The first time I saw X-Cache-Bypass, I thought it was an HTTP standard. It is not. A cache with no rule that reads it simply ignores it. This one sentence is the whole reason behind A Bypass Header Works Only Where a Rule Reads It.

A custom header is not a command. It is only a note. If nobody reads it, it is the same as not written.

Related: One HTTP Request, Cache Freshness: Fresh, Stale, and 304, CDN Terms on One Page, TTL Is Set in Three Places, A Bypass Header Works Only Where a Rule Reads It. Or go back to the series overview.

↑↓ navigate ↵ open esc close