Two Hard Things: caching bugs · Part 10
You cached an error. Forever.
Caching the promise dedupes concurrent requests, until it rejects and stays in the Map: every later caller gets the same failure long after the database recovered. Fix: four lines. On rejection, delete it from the Map, but only if it's still the same promise.
Comment below: Have you ever cached a rejection?
Two Hard Things: a series on the caching bugs you already ship, and how to fix them. "There are only two hard things in computer science: cache invalidation and naming things." (Phil Karlton) All code is real TypeScript on Node, typechecked before it went on screen, and every claim was reproduced against real Redis and Postgres.




