What the Cache Forgets: LRU & Eviction in SWR/React Query
You reach for TanStack Query and SWR every day — but do you know when they evict, and why a hand-rolled memo Map quietly leaks memory? Trace LRU eviction (hash map + doubly linked list), contrast LFU and TTL, reason about cache hits and misses, and cap a memoization Map at 100 entries. Anchored in 'why did React Query refetch this?'
Questions
- Not answered. Why did React Query refetch this?
- Not answered. What correctly distinguishes
staleTimefromgcTime? - Not answered. Which key does the LRU cache evict when
put('D', 4)runs? - Not answered. Why does an LRU cache's list need to be doubly linked?
- Not answered. What happens to this memo
Mapover a long-running server's lifetime? - Not answered. Which statements correctly describe a hash map + doubly linked list LRU cache?
- Not answered. Which statements about LRU, LFU, and TTL eviction are accurate?
- Not answered. What makes TanStack Query refetch a stale query?
- Not answered. Which statements correctly describe how a plain JS
Mapbehaves? - Not answered. After how many minutes is an inactive query garbage-collected?