Abhishek
Abhishek11mo ago

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
Indy
Indy11mo ago
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.
Michal Srb
Michal Srb11mo ago
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).
Abhishek
AbhishekOP10mo ago
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 ?
Michal Srb
Michal Srb10mo ago
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)

Did you find this page helpful?