11 Replies
Cool thanks.
Another quick question. Would i be able to do something like:
or would convex still not cache this function between multiple users?
Hmm I suspect it's cacheable across users but I'm honestly not sure
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?
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
All our convex functions currently have
const identity = await ctx.auth.getUserIdentity();
this line of code in themYeah that's normal
Are you seeing a generally high cache rate overall?
apart from not knowing if cached responses work across users
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
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 / etcGood 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
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.
got it thanks