Back to the Catalog
react
frontend
performance
data-structures

What the Cache Forgets: LRU & Eviction in SWR/React Query

10 questions

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

  1. Not answered. Why did React Query refetch this?
  2. Not answered. What correctly distinguishes staleTime from gcTime?
  3. Not answered. Which key does the LRU cache evict when put('D', 4) runs?
  4. Not answered. Why does an LRU cache's list need to be doubly linked?
  5. Not answered. What happens to this memo Map over a long-running server's lifetime?
  6. Not answered. Which statements correctly describe a hash map + doubly linked list LRU cache?
  7. Not answered. Which statements about LRU, LFU, and TTL eviction are accurate?
  8. Not answered. What makes TanStack Query refetch a stale query?
  9. Not answered. Which statements correctly describe how a plain JS Map behaves?
  10. Not answered. After how many minutes is an inactive query garbage-collected?