#Does useQuery caches? Every time I refresh the page I see the call getting log in the dashboard.
4 messages · Page 1 of 1 (latest)
Hi @stray ridge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, useQuery does utilize caching, but the behavior you're observing is expected. Let me explain:
-
Client-side caching: The Convex React client does cache query results on the client side. When multiple components use the same query with identical arguments, the client deduplicates these calls to avoid unnecessary network requests Discord thread (https://discord.com/channels/1019350475847499849/1260592429132812379).
-
Server-side caching: Convex also caches query results on the server side. If multiple clients request the same query with the same arguments, they may receive a cached response Convex Docs (https://docs.convex.dev/functions/query-functions#caching--reactivity--consistency).
-
Page refresh behavior: When you refresh the page, the client-side cache is cleared, and the query is executed again. This is why you see the call being logged in the dashboard every time you refresh Discord thread (https://discord.com/channels/1019350475847499849/1294278956245319700).
-
Subscription behavior:
useQuerysets up a subscription to the query, which means it will automatically update when the underlying data changes. This is part of Convex's reactivity feature Convex Docs (https://docs.convex.dev/functions/query-functions#caching--reactivity--consistency).
If you want to maintain cache across page refreshes or component unmounts/remounts, you might want to look into using the ConvexQueryCacheProvider from the convex-helpers package. This can help keep query subscriptions active even when components are unmounted, potentially reducing unnecessary server calls Discord thread (https://discord.com/channels/1019350475847499849/1301891937556762634).