erquhart
erquhart2mo ago

Yes that works

Yes that works
11 Replies
Jamal
Jamal2mo ago
Cool thanks. Another quick question. Would i be able to do something like:
export const getData = queryWithUser({
args: {},
handler: async (ctx) => {
if (space.isPrivateOnly) {
// Perform auth checks only if this condition is met
}
return { ... }
},
});
export const getData = queryWithUser({
args: {},
handler: async (ctx) => {
if (space.isPrivateOnly) {
// Perform auth checks only if this condition is met
}
return { ... }
},
});
or would convex still not cache this function between multiple users?
erquhart
erquhartOP2mo ago
Hmm I suspect it's cacheable across users but I'm honestly not sure
Jamal
Jamal2mo ago
Okay, i guess we will have to test it ourselfs. Its just hard to tell why functions are being cached. because in the dashboard if multiple users are calling functions which cache hitting for which user?
erquhart
erquhartOP2mo ago
It's less about the user and more about the inputs Consider auth to be just another input If I call a function that takes a number, and I pass the number 2, further queries with the same arg can get a cached result But whether and how caching can work across authenticated functions for different users, whether auth plays a role in the function or not, I'm honestly not sure Seeing if someone can chime in
Jamal
Jamal2mo ago
All our convex functions currently have const identity = await ctx.auth.getUserIdentity(); this line of code in them
erquhart
erquhartOP2mo ago
Yeah that's normal Are you seeing a generally high cache rate overall? apart from not knowing if cached responses work across users
Jamal
Jamal2mo ago
Yes, when hitting our convex functions myself, my functions are being cached at the 60%-100% range This is the part im not sure about, and want to make sure I understand how to control
ian
ian2mo ago
The cache is based on the user token only if you call ctx.auth.getUserIdentity() (or call some library that calls it, e.g. getAuthUserId). So if you don't call that, the cache is shared between all users. If you call that, it'll only be shared for clients with the same user token. Then the caching is also based on what tables/env variables you read / etc
Jamal
Jamal2mo ago
Good to know, thanks ian! @Ian When a mutation is ran, are the queries inside also cached? or @erquhart if you know the answer to this
erquhart
erquhartOP2mo ago
Caching applies to an entire query function, individual ctx.db.query calls within a function of any type aren't currently cached across function calls.
Jamal
Jamal2mo ago
got it thanks

Did you find this page helpful?