←back to thread

Tower Defense: Cache Control

(www.jasonthorsness.com)
58 points jasonthorsness | 2 comments | | HN request time: 0.397s | source
Show context
ec109685 ◴[] No.44006778[source]
Regarding stale-while-revalidate, the author calculates maximum load like this: “With the options available on hn.unlurker.com, there are only 10 * 12 * 8 * 2 or 1920 possible combinations, refreshed at most once every 15 seconds”

That math works until it doesn’t. If for some reason there’s a greater than 15 second response, the cache will open the floodgate and won’t return any cached response until the cache is full.

Similarly, errors need to be accounted for. If the server returns a 500, is it configured to be cached? Is stale-while-error configured so the error state doesn’t take the server down?

replies(2): >>44007741 #>>44008459 #
1. tshaddox ◴[] No.44008459[source]
Also, wouldn't each CDN node maintain its own cache and thus its own state-while-revalidate timer? Or is the implication that this is using a tiered cache where there's only a single CDN node that connects to the origin server?
replies(1): >>44008651 #
2. jasonthorsness ◴[] No.44008651[source]
Good point. I guess this depends on Vercel's cache topology and whether it uses multiple layers. I would have thought they would cache the output of the origin function in a cache right at the origin but I can't find anything about this in the docs so likely not. As an alternative, they do allow caching the fetch to the API in their "data cache" so I'll probably need to enable that to protect the VPS in the way I intend.