TanStackT
TanStack14mo ago
5 replies
foolish-indigo

Setting gcTime on prefetched data

Scenario:
Using prefetchQuery on the serverside to fetch some data for the page. The page that is loaded does not actively have a useSuspenseQuery call for that particular piece of data, it is only used on other pages. The useSuspenseQuery sets a gcTime of Infinity to disable garbage collection on the prefetched data. The prefetch call also sets gcTime of Infinity.

The problem:
The prefetched data stored in the query cache gets a gcTime of "5 minutes" when there are no active queries subscribed to it, since there is nobody there to tell it otherwise. That means there doesn't seem to be a way to keep the prefetched data around until it's actually used by a query hook, without just calling a "dummy" hook on every page to make sure gcTime is set?
Was this page helpful?