T
TanStack2mo ago
absent-sapphire

Tanstack-query: expo application when we close/kill the app the store should be cleared?

I'm working on a react-native application and one of the issues that we have is for example this hook:
const {
data: exampleData,
} = useQueryTanstack({
queryKey: ['example'],
queryFn: getExample,
enabled: !!account.id,
staleTime: 1000 * 60 * 2,
});
const {
data: exampleData,
} = useQueryTanstack({
queryKey: ['example'],
queryFn: getExample,
enabled: !!account.id,
staleTime: 1000 * 60 * 2,
});
getExample will cache the response for 2 minutes (staleTime: 2 * 60 * 1000). If another system updates the /example data during that window, TanStack Query won’t auto-notice unless a refetch is triggered (mount/focus/reconnect/explicit refetch), which is expected. Question: If we kill or close the app before those 2 minutes expire, will the next launch refetch from the endpoint, or will we still see cached store values? Context: I’d like to confirm whether the in-memory store is cleared on app close. I’m considering:
useQuery({
queryKey: ['orders', accountId, orderType, page, ignorePagination],
queryFn: getOrders,
enabled: !!accountId,
staleTime: 1000 * 60 * 2,
refetchOnMount: 'always',
refetchOnWindowFocus: 'always',
refetchOnReconnect: 'always',
})
useQuery({
queryKey: ['orders', accountId, orderType, page, ignorePagination],
queryFn: getOrders,
enabled: !!accountId,
staleTime: 1000 * 60 * 2,
refetchOnMount: 'always',
refetchOnWindowFocus: 'always',
refetchOnReconnect: 'always',
})
I didn’t find much documentation confirming this in React Native.
2 Replies
correct-apricot
correct-apricot2mo ago
Question: If we kill or close the app before those 2 minutes expire, will the next launch refetch from the endpoint, or will we still see cached store values? Context: I’d like to confirm whether the in-memory store is cleared on app close. I’m considering:
Because you are using default in memory store, then it depends on how android/iOS manages memory. Like, "does android/iOS clears memory if the application is closed or killed" kind of stuff.
absent-sapphire
absent-sapphireOP2mo ago
and there's a way to use something else ? or how I should take more control about those stuff? I mean, instead of just relegate to refresh always I can just refresh if the app is killed Could you point me to any documentation or resources where I can read more about that?

Did you find this page helpful?