shandy
shandy15mo ago

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() calls within the Route Handlers as the same fetch() calls are happening separately within SSR via 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() takes in the 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() automatically opt out of /app Route Handler caching? And if so, is there a way to enable caching? Thanks in advance <:Sadge_pray:860473532700819506>
Routing: Route Handlers
Create custom request handlers for a given route using the Web's Request and Response APIs.
0 Replies
No replies yetBe the first to reply to this messageJoin