T
TanStack3y ago
flat-fuchsia

Completely disable cache for a single query?

How do I completely disable caching for one query? I have set cacheTime: 0 but this code seems to always cache its result:
const { data, status } = useQuery('me', () => ky.get('api/me').json<User>(), {
enabled: shouldReauth,
cacheTime: 0
})
const { data, status } = useQuery('me', () => ky.get('api/me').json<User>(), {
enabled: shouldReauth,
cacheTime: 0
})
2 Replies
rival-black
rival-black3y ago
You probably want a staleTime of infinity
other-emerald
other-emerald3y ago
staleTime: Infinity caches forever. I'm not sure what "disabled caching" would do, how should that work? You have to put fetched data in some sort of state, otherwise, you can't render it ...

Did you find this page helpful?