Back to the catalog

Cache eviction in TanStack Query and SWR: staleTime, gcTime & LRU

10 questions

You probably use TanStack Query or SWR every day. Start with a familiar puzzle, 'why did React Query refetch this?', and learn how staleTime and gcTime decide when cached data is refetched or dropped. Then trace an LRU cache built from a hash map and a doubly linked list, compare it with LFU and TTL, and see why a memo Map with no size limit leaks memory.

Questions

  1. Not answered. Why did React Query refetch this?
  2. Not answered. What's the difference between staleTime and 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 on a long-running server?
  6. Not answered. Which statements about a hash map + doubly linked list LRU cache are true?
  7. Not answered. Which statements about LRU, LFU, and TTL eviction are true?
  8. Not answered. What makes TanStack Query refetch a stale query?
  9. Not answered. Which statements about a plain JS Map are true?
  10. Not answered. After how many minutes is an inactive query garbage-collected?