How can I cache a single procedure?
I've seen the docs on caching here: https://trpc.io/docs/caching
But that is caching the entire app router.
my app router has many "subrouters" (Not sure what you call them) and I need different cache times for different "procedures" in those routers.
For example I have some data that I would only want a 5 minute cache time for, but other data that can be cached for a week with no issues.
How can I apply a specific cache time to a procedure in trpc?
I tried using the
paths
array in the app level caching, but it seems to sometimes include both paths that I want long caching for and paths that needs short caching? So I don't know how I would be able to use that to change the cache time properly.
For example I have a component that does multiple trpc queries, where some of those can be cached for a week without problems and others needs to be updated at least once a minute.Response Caching | tRPC
The below examples uses Vercel's edge caching to serve data to your users as fast as possible.
4 Replies
Would still love some help with this ๐
Unknown Userโข2y ago
Message Not Public
Sign In & Join Server To View
So if you still want batching to work I'd do a middleware that reads metadata of the called procedure and cache the data in for instance Redis
I do guess it would be good to have access to more metadata of the called procedures in the responseMeta too... This could help https://github.com/trpc/trpc/issues/3152
GitHub
feat: add info about calls to
createContext()
-options ยท Issue #31...Describe the feature you'd like to request Add more meta data about the request when creating context Describe the solution you'd like to see export async function createContext(opt...