trpc caching procedure calls for queries in the same batch
Hello,
I am using nextjs and trpc server components, using trpc to prefetch queries. All of the requests on this page are protected by a procedure called
protectedGuildPermissionsProcedure
which essentially checks that the user has the right permissions to access the data that is returned.
procedure:
Is there some way of telling TRPC to cache the response from the procedure for all batched requests so wont do the same permission check, even though it has already been done?
As it currently stands, this expensive procedure will run 5 times, one for each api request that is prefetched.
Yes, I could cache this in redis (which I do) but if there is no cache to quickly see if they have permissions each query will have to run the expensive function and it could make the page take up to 30 seconds to load.
I'm thinking I could use some sort of redis lock, but it still seems a little inefficient having 5 queries that run at he same time (same trpc batch) all getting the same data from redis?0 Replies