Sitemap
System Design & Architecture Deep Dives

How real systems are designed, where they break, and why. System design and architecture deep dives for backend engineers

Member-only story

HTTP Caching Explained: What Cache-Control, ETag and 304 Actually Do, Measured

--

no-cache doesn’t mean “don’t cache”, a response with no caching headers gets cached anyway, and one public header let a shared cache hand one user’s session cookie to the next. Twelve rules, each run against a counting origin.

Press enter or click to view image in full size
The two questions every HTTP cache asks: is my copy still fresh, and if not, has it changed? Cache-Control answers the first, ETag and 304 answer the second, and private, s-maxage and Vary decide who is allowed to share the copy.

Three requests for the same URL, through a cache, and what the origin server saw:

Cache-Control: no-cache    client saw [200, 200, 200]   origin saw 3: ['plain', 'INM', 'INM']
Cache-Control: no-store client saw [200, 200, 200] origin saw 3: ['plain', 'plain', 'plain']

Both headers sent three requests to the origin, so they look the same from far away. They aren’t. With no-cache, the cache stored the response, and the second and third requests carried If-None-Match, the cache asking "I have this version, is it still current?" The origin answered 304 Not Modified with no body. With no-store, the cache kept nothing and downloaded the whole response every time.

Most developers read no-cache as "don't cache this". It actually means "cache this, but check with me before every use". That one misreading explains a lot of slow pages and a few data leaks. HTTP caching is not one setting. It is two separate questions, freshness and validation, plus a third about who may share a stored copy, and each header answers…

--

--

Full stack Developer, Architect, Lead , Agile

See more from me

System Design & Architecture Deep Dives
System Design & Architecture Deep Dives

Published in System Design & Architecture Deep Dives

How real systems are designed, where they break, and why. System design and architecture deep dives for backend engineers