I have read React-Query docs, still I do not understand how to use staleTime & cacheTime for data caching.
I want to store data for 2 mins in the cache after first-time API call.No matter component mounts or unmounts, I don't want an API call for 2 mins after the first time get data. I used this but it does not call API after 2 min if i use staletime only & it's call API every time (on-mount component & unmount component ) if I use cachetime only.
so, what is the problem? & what is the best way to do this?
const query = useQuery("getuserlist", getusertList, {
// staleTime: 120000,
cacheTime: 120000,
});