Problem Statement
Explain negative caching and its risks. Where is it useful?
Explanation
Negative caching stores the fact that a lookup returned no result to shield the database from repeated misses. Use short TTLs so real new data appears soon. It is useful for user handles, feature flags, or sparse entities where misses dominate. The risk is hiding recent inserts or fixes, so bound TTL tightly and add explicit invalidation on create.
Code Solution
SolutionRead Only
cache.set("user:handle:foo", null, 30s) // miss remembered for 30s