Cache invalidation
Is there any way to invalidate the cache akin to attaching a query key in react query?
Currently I have a a few queries that leverage auth to pull in the correct information, but if this variable (switching to organziation) changes on the frontend, then the queries do re-fire.
Would the recommended approach be passing the potential variable that changes in as an arg even if it's not used in querying the data?
3 Replies
That works, yep. Generally Convex is all about perfect caching where you don't need to bust the cache like this, so this case is interesting. Sounds like this is a field in an identity token? Is this org changed using Clerk? I wonder if a new ID token is being reported from Clerk. If you do use a cache-busting extra argument, do you see the correct organization reported in the Convex function right away?
I'll test this. This is exactly the case I'm changing the org using clerk. So I grab the orgId by passing it inside of the convex JWT template inside the "nickname" property.
Is there a better way to do this?
Similarly to https://discord.com/channels/1019350475847499849/1112419233452785754 I’d suggest passing the orgId in explicitly. Either everywhere it’s required or you can create a mutation for syncing the orgId from a useEffect.