Caching does not work with trpc in Next, what would you do?

Hi, I someone in trpc discord said: 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) And this is a big problem, what's a good alternative if I really need to cache my trpc calls? Also, maybe t3 stack should change trpc? Is there any other way to cache db calls? Next cache works only for fetch calls. @nexxel is this an issue for t3? Thanks
Response Caching | tRPC
The below examples uses Vercel's edge caching to serve data to your users as fast as possible.
next.config.js Options: headers | Next.js
Add custom HTTP headers to your Next.js app.
10 Replies
Kenzo
Kenzo5d ago
@julius I don't like to @ ppl but I saw your a maitainer of trpc. Does next version of trpc fix it? Hi? any idea?
Aleed.dev
Aleed.dev5d ago
ummm don't know if this should work for you https://react.dev/reference/react/cache.
julius
julius5d ago
either React.cache for deduplication within the same request or Next.js' unstable_cache for persistent caching
Kenzo
Kenzo5d ago
Oh I really appreciate it Julius 🫡 Got no answers in trpc discord, and saw nothing on their docs I love trpc, But it may need an update on their docs
julius
julius5d ago
it's hard to put out generic recommendations when there are not yet a stable api in next requires maintenance "easier" to just leave it out and let people who want to use the unstable apis figure out the integration themselves
Kenzo
Kenzo5d ago
True,caching methods are outdated in trpc.. But I saw you are tweaking trpc Fetch. Do you think stale while revalidate will work properly ?
julius
julius5d ago
True,caching methods are outdated in trpc.. But I saw you are tweaking trpc Fetch.
How so? http caching should work same as before. But you probably also wanna cache the RSC invocation and that can't be done using http headers honestly I wouldn't expect an official caching story in the trpc docs until next has figured it out on their end they are redoing it in 15 who knows they might revert it in 16 again... we're not gonna put in the effort to support all of these iterations as we simply don't have the time or resources to do so
Kenzo
Kenzo5d ago
Yep I see. Next changes too much We cannot change trpc Fetch headers, that's what I meant, so we can't use next fetch things like stale while revalidate That's what I wanted to say XD
julius
julius5d ago
there is no fetch from server component and from client component, yes you can change the fetch
Kenzo
Kenzo5d ago
Ah okay, so for now I'll use unstable cache, ty!
Want results from more Discord servers?
Add your server
More Posts
trpc server actions: experimental_nextAppDirCallerSo, I saw this in one of the recent videos that you t3 rockstars are doing gods work and adding servImports and exports not working turborepoUsing create-t3-turbo I have declared Projects in the db schema: ```ts // schema.ts export const PrNext.js Slow Page Load in Dev upto 2 mins```jsx /** @type {import('next').NextConfig} */ const nextConfig = { // reactStrictMode: true,Serverless function runs right after edge middleware is invoked, overriding built-time dataHi all, I'm running a content focused website for my company using sanity for cms (with groqd for tyNoob can't get getStaticProps() to work – props in my Page are always undefinedNot a noob to programming in the slightest, but extremely noob to React/ NextJS. I wanted to try buiWhats the point of this ternary operator in the nextjs homepage of Create T3 App?I thought i knew my nextjs, but there is a ```{hello ? hello.greeting : "Loading tRPC query..."}``` Unauthorized 403 errorFailed to load resource: the server responded with a status of 403 (Forbidden): uploadthing-prod.s3.About Theo's take of not destructuring propsI can't remember in what video exactly, but I heard Theo saying something about using component propHow to generate files and upload to Github?I'm trying to generate files on my nextjs/vercel app and then upload to a new private repo on the usZod, Non numeric stringHow can i with zod enforce something to be a string and make sure it doesnt contain any numbers