P.S.Nikhil
P.S.Nikhil8mo ago

How to cache trpc server request next.js app router

is it the right way ctx.headers.set( "Cache-Control", "public, max-age=43200, stale-while-revalidate=120, immutable", );
8 Replies
Fossil
Fossil4mo ago
Did you figure this out? I am stumped
P.S.Nikhil
P.S.Nikhil4mo ago
You can use react cache to handle client-side caching, but I haven't figured it out for server api level caching
Fossil
Fossil4mo ago
Yea lots of options with clientside cacheing. Kinda ridiculous there's no docs for app router cacheing Currently documented tRPC cacheing methods (https://trpc.io/docs/server/caching) won't work as they rely on setting headers which NextJs now overrides (https://nextjs.org/docs/app/api-reference/next-config-js/headers#cache-control)
Kenzo
Kenzo2w ago
omg.. I've been trying this for so long today so, there is no way to Next caches trpc calls?
BeBoRE
BeBoRE2w ago
You cannot set Cache-Control headers in next.config.js for pages or assets, as these headers will be overwritten in production to ensure that responses and static assets are cached effectively.
Doesn't say anything about the app router and API routes.
BeBoRE
BeBoRE2w ago
Caching on Vercel's Edge Network
Vercel's Edge Network caches your content at the edge in order to serve data to your users as fast as possible. Learn how Vercel caches works in this guide.
Kenzo
Kenzo2w ago
yeah but i did not found any way to modify fetch headers of TRPC anyway, Julius said (in other discord) that a good alternative if I need to force cache is use unstable cache
Fossil
Fossil2w ago
Can you link to this Kenzo?