Slewt
Slewt3mo ago

Convex’s use of server vs client caching

I’ve been searching for any blog post or docs that break this topic down more. I know convex will cache server function queries so all clients that call the same function query will get the cached response. But what about repetitive calls from the client? I’ve seen a little reference that convex does client caching in 1 post but zero other info about it that I can find so far. I’m trying to decide how to architect the query patterns for some dynamic data heavy pages. Specifically large custom spreadsheets that every column, row, and cell value can be changed (though not frequently) and shared between users, organizations, teams. So striking the right balance of how granular to make the query subscriptions is important. And how this will affect the function call quotas for convex matters even if they are generous. From what I’ve seen, each server function call counts toward the usage quota whether it’s cached or not. What about local cache responses? Is that even a thing or do I need to write my own local cache? There’s guidance around using convex for state, but if it doesn’t local cache and charges for each function call it’s not really valid for state usage. Appreciate any suggestions around the topic.
3 Replies
Convex Bot
Convex Bot3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
allen
allen3mo ago
Here is some info on local caching using convex-helpers. https://www.youtube.com/watch?v=ZgxDlSUGpfE
Convex
YouTube
Can your database do this? Ep. 1: Magic caching
A Next.js app with no query cache? Jank. One with a cache? No more jank, but now we need to deal with cache invalidation and application consistency. Ugh. But with Convex's magic query cache, Convex's powerful subscriptions are cached, not merely values. So you get the best of both words. Repository here: https://github.com/jamwt/cached-dmv ...
jamwt
jamwt3mo ago
Good question, @Slewt . (1) by default the convex client deduplicates all subscriptions to the same query into a single subscription. so you don't have to worry about 5 uses of the same useQuery invoking 5 different server-side function calls. it will be just one (2) using the library allen links to from the video above, you can avoid (some) re-invoking functions on SPA route changes by keeping subscriptions alive (3) re: "even if the server function is cached, it still counts the same as not cached". Yes, this is true on our current paid plan, "Pro". We're going to be launching a "Scale" plan for customers with more traffic that passes through cost reductions for cache hit behavior. Sites at scale on Convex end up getting pretty good at query caching design, and so it only makes sense to pass long the cost saving when the site efficiency improves. let me know if that addresses your questions, or if I missed something most of why (3) doesn't exist yet is like, pricing and packaging is really hard and takes a lot of time. especially b/c you never want to get pricing wrong and you never want to raise prices, only lower them

Did you find this page helpful?