useQuery and fetchQuery are cached?
Just like in nextjs 14 fetch automatically caches the response of same api does same thing happens with useQuery and fetchQuery in convex ?
4 Replies
Convex automatically caches in the convex backend itself. You don't have to worry about the consistency of the cache since Convex is automatically doing that as well.
fetchQuery uses cache: no-store, to rely on the cache on the Convex side and avoid surprising Next.js caching behavior.
useQuery “caches” on the client (calling useQuery with the same arguments from two different components results in only a single function call on the backend, which itself might be cached).
Thank you for clearing stuff , means a lot @Michal Srb @Indy
@Michal Srb so calling fetchQuery with the same parameter and everything same from two different components will make a two different call on server end ?
I think the React cache still applies, so inside the same render it should be a single fetch request. Can you try it out and let me know? It should be easy to see from the Convex dashboard.
(there is a React cache and Next.js/Vercel cache)