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
Did you figure this out? I am stumped
You can use react cache to handle client-side caching, but I haven't figured it out for server api level caching
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)
omg.. I've been trying this for so long today
so, there is no way to Next caches trpc calls?
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.
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.
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
Can you link to this Kenzo?