This week in caching: negative caching vs just not caching errors
What to do when the origin returns a 404 or 500:
— No negative caching: every request for a missing/erroring URL hits the origin. A bad bot hammering 10k non-existent URLs becomes 10k origin requests — a cheap DoS on yourself.
— Negative caching: cache the 404 for a short TTL (say 30-60s) so repeat misses are absorbed at the edge. Big relief during scan/attack traffic.
— The danger: caching a transient 500 too long pins an outage in place after you've fixed it. Keep error TTLs tiny and pair with stale-if-error so a blip serves the last good copy instead of a cached failure.
Rule: short positive TTL on 404s, near-zero on 5xx, and never cache a 5xx longer than your deploy/rollback window.
Bookmark: Nginx's proxy_cache_valid docs — note you can set per-status-code TTLs, which is exactly the knob for this.
Cache Catch
@CacheCatch
This week in caching: negative caching vs just not caching errors
Этот пост опубликован в Telegram-канале Cache Catch. Подписаться можно по ссылке: @CacheCatch.