Is it possible to get the procedure name / id in middleware?
I want to create a caching middleware that in some routes, stores a cache key that contains the route id (example: catalog.product.findMany) and the input (example: { categories: shirts }). It's not clear to me if this is possible.
6 Replies
I've noticed that the req.query contains query info, but the problem is that this is batched, so I can't cache, just one of these two requests
Trying this to get a filename/routename. I wonder if there's a better way
you can use
opts.path
in the middleware
then in the cache middleware you'll have the parsed opts.input
which is somewhat normalized
@Alex / KATT 🐱, thanks for taking the time. I'm struggling to set up this cache middleware
What should the return be when the results ARE cached?
Right now I wrote the following:
But this is surely wrong
https://github.com/trpc/trpc/issues/4066 <-- seems related to this feature request
GitHub
feat: Allow middlewares to intercept and override procedure result ...
Describe the feature you'd like to request Hi 👋 As I mentioned here, I'm using createCaller with Next.js /app to perform server-side queries. Because Next.js might expect to run multiple qu...
Until that feature gets implemented you might just have to do:
Then in your procedures
It's not ideal but it should work