
Ask HN: What is the most clever web caching strategy your company is using? - bflesch
It seems nowadays everyone is using static assets which are cached forever by the CDN, and changes are pushed to the users by adding some sort of content hash into the filename. You benefit from the browser keeping all files in the cache forever, and yet you can deploy changes very easily by simply using a different filename for the updated assets.<p>Yesterday I became aware of a different technique, for which I couldn&#x27;t find extensive documentation yet: We&#x27;re building a social network type website and I found out that you can (and should) mix Etag-based caching and the traditional &quot;Cache-Policy: private, max-age=XXX, must-revalidate&quot; on the same route, depending on which user is requesting the data.<p>This approach solves the issue that you want to cache all your api route responses at the client, but if the user wants to change some of their own data (which can be changed by the user but is also fetched through the same API) you can reply to the user&#x27;s own objects with the dynamic Etag instead of the forever-lasting &quot;Cache-Policy&quot;.<p>It is a pretty simple concept to address caching not only on a per-route, but also on a per-user-per-route level.<p>In the end, it left me wondering what other things in terms of web caching I have been overlooking in the past few years. I&#x27;d appreciate if you could share your stories.
======
Piskvorrr
I have yet to see a `Cache-Policy` header; assuming `Cache-Control`.

Now: do you have a good reason for must-revalidate, or is it just "it was on
SO, stick it in there"? Without further headers, this does nothing and wastes
16 bytes per request ;)

Conditional requests can indeed be mixed with expiration; consider looking at
Last-Modified while at it.

For largish data, byte-serving is not quite caching, but still comes in handy.

Last but not least, Cache-Control: immutable and/or content hash are still
viable - but especially for content you _do_ expect to be around Forever(tm).

Check also the Age header, and Expires - but that's been mostly superseded by
clever tricks with 304s and Cache-Control.

