In this lesson, we explore how TanStack Router caches data returned from a route's loader
function.
This caching mechanism is focused on the data fetched by the loader
(!), not the component's rendered markup (i.e. unlike React's memo
).
We learn how to view cached data using TanStack Router DevTools, where we can see details like the age
, staleTime
, and garbage collection gcTime
for each route's loader data.
These settings control how long data remains fresh and when it is refetched or removed from the cache. For example, the stale time determines how long cached data is considered fresh before being refetched in the background, while the GC time controls how long data is kept after a route is unloaded.