T
tRPC

❓-help

Disable trpc route cahce?

T.thatguyjamal10/26/2023
import { protectedProcedure, router } from "@/lib/trpc/server/trpc";
import { TRPCError } from "@trpc/server";

export const clientRouter = router({
get: protectedProcedure.query(async ({ ctx }) => {
const { id: user_id } = ctx.session.user!;

if (!user_id)
throw new TRPCError({
code: "NOT_FOUND",
message: "No user session found",
});

let { data: client, error } = await ctx.supabase
.from("clients")
.select("*")
.eq("user_id", user_id)
.single();

if (error) {
throw new TRPCError({
code: "BAD_REQUEST",
message: error.message,
});
}

return client;
}),
});
import { protectedProcedure, router } from "@/lib/trpc/server/trpc";
import { TRPCError } from "@trpc/server";

export const clientRouter = router({
get: protectedProcedure.query(async ({ ctx }) => {
const { id: user_id } = ctx.session.user!;

if (!user_id)
throw new TRPCError({
code: "NOT_FOUND",
message: "No user session found",
});

let { data: client, error } = await ctx.supabase
.from("clients")
.select("*")
.eq("user_id", user_id)
.single();

if (error) {
throw new TRPCError({
code: "BAD_REQUEST",
message: error.message,
});
}

return client;
}),
});
I have this code to fetch some data from my db and return it, however if i call the endpoint again, the data is the same even if the db is different? Does trpc cache the old data on new request? If so i dont want this
T.thatguyjamal10/26/2023
However when i go to http://localhost:3000/api/trpc/getClient and test i get the fresh data on every request?
AEAhmed Elsakaan10/26/2023
this is because of react-query’s caching if you set cacheTime to 0 in your useQuery call options, it won’t cache the response
T.thatguyjamal10/26/2023
but im using
export const trpc = experimental_createTRPCNextAppDirServer<AppRouter>({
config() {
return {
transformer: superjson,
links: [
loggerLink({
enabled: () => process.env.NODE_ENV === "development",
}),
experimental_nextHttpLink({
batch: true,
url: getUrl(),
headers() {
return {
cookie: cookies().toString(),
"x-trpc-source": "rsc-http",
};
},
}),
],
};
},
});
export const trpc = experimental_createTRPCNextAppDirServer<AppRouter>({
config() {
return {
transformer: superjson,
links: [
loggerLink({
enabled: () => process.env.NODE_ENV === "development",
}),
experimental_nextHttpLink({
batch: true,
url: getUrl(),
headers() {
return {
cookie: cookies().toString(),
"x-trpc-source": "rsc-http",
};
},
}),
],
};
},
});
The Nextjs server trpc so it only has the query method on it
AEAhmed Elsakaan10/27/2023
hmm idk about that one tbh, @julius ? app router master
Jjulius10/27/2023
The ”new”, experimental, nextHttpLink does set cache tags, so that’s why you’re seeing that behavior, it’s expected. You can set a revalidation time on how long you want the fetch request to be cached for in the link options, or just use the old/normal httpLink/httpBatchLink if you dont want any caching

Looking for more? Join the community!

Recommended Posts
How do you set headers or cookies in procedure ?Having trouble figuring out how to set headers within a procedure in Next 13.Why use unstable_httpBatchStreamLink in React server components?When using create-t3-app I noticed that they were using `unstable_httpBatchStreamLink` in their `TRPUnsafe return of an `any` typedI am using TRPC with Prisma. I can't seem to get rid of the TypeScript ESlint error. ``` import { zVanilla Client AuthenticationHow to authenticate using the vanilla client? I want to consume this route as the authenticated userGeneric Zod as Input TypeI'm not positive if this is a TRPC question, typescript in general, or failure to understand Zod in Incompatible Router TypesI am working on a trpc implementation for sveltekit. I attached a screenshot of the createContext nextjs app router, "fs", "os", "zlib-sync" and trpc experimental edge RouterEnvironement: Turborepo + pnpm What's wrong: when I tried to build nextjs, the error is like this TS4111: Property 'error' comes from an index signature, so it must be accessed with ['error'].I am trying to use trpc with AnalogJs, an Angular meta framework and Nx. We use the @nx/vite builderTypeError: Cannot read properties of null (reading '_def')As the title says, I get the following: TypeError: Cannot read properties of null (reading '_def') I wanna add a localStorage persister, but I'm getting errors for hydration:I wanna add a localStorage persister, but I'm getting errors for hydration: ```js const persister =error route always getting 500 from trpc error? (next13/approuter)I've got this condition for throwing in my trpc procedure: ```ts if (!userClerkProfile) { force-cache planetscale errortrying to use the trpc API from RSCs fails and gives the following error ```log result: { data:What is the pattern for unsubscribing from a subscription?Hi there! I'd like to prevent unnecessary connections to a websocket server across multiple renders.How to add a short delay between requestsEnvironment: nextjs 13, node 18, npm, trpc 10.9.0 I'm wondering if it's possible to add a short delGlobal metadata / filters: Re-validate all queriesHi all, Simple question, I'm looking for the most efficient way to add some global state to all queAttempted import error: 'hashQueryKey' is not exported from '@tanstack/react-query' issuei'm getting this error while trying trpc with latest next version , i tried downgrading but got anotTRPC cant handle ErrorHi, can someone please help me: https://stackoverflow.com/questions/77333318/trpc-handle-trpcerrorI want to create a wrapper for TRPC.init but I can't seem to get the context type correct.I want to get wrap trpc.init