tRPCttRPC
Powered by
shandyS
tRPC•3y ago•
1 reply
shandy

Does `fetchRequestHandler()` automatically opt out of /app Route Handler caching?

I noticed that Next.js always skips cache for my TRPC API Route Handlers even though the request URLs are identical and the cache/revalidate config calls for persistent caching. I feel confident it has nothing to do with the
fetch()
fetch()
calls within the Route Handlers as the same
fetch()
fetch()
calls are happening separately within SSR via
createCaller()
createCaller()
and are being cached within Next's Data Cache as expected. However, I just read this from Route Handler docs:

You can opt out of caching by: Using the Request object with the GET method.

And I see that
fetchRequestHandler()
fetchRequestHandler()
takes in the
Request
Request
as a param:

import { fetchRequestHandler } from "@trpc/server/adapters/fetch";

import { appRouter } from "@/server/routers/_app";
import { createContext } from "@/server/trpc";

const handler = (req: Request) =>
  fetchRequestHandler({
    endpoint: "/api/trpc",
    req,
    router: appRouter,
    createContext,
  });

export { handler as GET, handler as POST };
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";

import { appRouter } from "@/server/routers/_app";
import { createContext } from "@/server/trpc";

const handler = (req: Request) =>
  fetchRequestHandler({
    endpoint: "/api/trpc",
    req,
    router: appRouter,
    createContext,
  });

export { handler as GET, handler as POST };


Does
fetchRequestHandler()
fetchRequestHandler()
automatically opt out of /app Route Handler caching? And if so, is there a way to enable caching? Thanks in advance Sadge_pray
Routing: Route Handlers
Create custom request handlers for a given route using the Web's Request and Response APIs.
Routing: Route Handlers
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How to opt out of caching an API in trpc NEXT/SSR?
ephremEephrem / ❓-help
2y ago
nextjs app router `fetchRequestHandler`'s createContext doesn't run.
VilianVVilian / ❓-help
3y ago
Set custom header for fetchRequestHandler
typedefTtypedef / ❓-help
3y ago