Fetch caching in Server actions #50045
-
I am using the "use server";
import { kafka } from "@/utils/kafka";
export async function createMessage() {
console.log("action");
await kafka.producer().produce("send_message", { name: "Test" });
} However, since it uses I am wondering if there is something like: "use server";
//disable caching
export const revalidate = 0;
export function myAction() { ... } |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 11 replies
-
I am very supprised there hasn't been any response to this discussion since May. I am experiencing the exact same problem. Will probably go back to using regular API routes for now... |
Beta Was this translation helpful? Give feedback.
-
I just encountered the same issue using Drizzle with the neon serverless connection. The caching docs do not go into detail into how to disable caching for Server Actions specifically but it seems using export async function signIn(formData: FormData) {
// disable cache for this server action
const _cookies = cookies()
// library calls using fetch
} This 'magic' approach to caching at the cost of predictability really needs some work in my opinion. |
Beta Was this translation helpful? Give feedback.
-
Yeah the automatic caching of third party libraries using fetch as well causes many issues and there isnt a way to disable it without disabling all the other fetch in a page |
Beta Was this translation helpful? Give feedback.
-
I searched for ages to solve this problem with @triggerdotdev client in a server action, had read the next docs over and over and tried the same as you guys - thank you @romeobravo for this solution (although not a fan of magic solutions at least it works). |
Beta Was this translation helpful? Give feedback.
-
This was a gotcha for us too, using a third-party lib that had its The Could there please be a clearer way to opt an individual component out of caching without this workaround? |
Beta Was this translation helpful? Give feedback.
-
Using drizzle with neon-serverless too, I have an app router setup. Setting this at the top of the page.js file solved it for me: |
Beta Was this translation helpful? Give feedback.
-
I think this might work for you, it's on the official website : https://nextjs.org/docs/app/api-reference/functions/unstable_noStore |
Beta Was this translation helpful? Give feedback.
-
i found that using drizzle no caching was being applied on the db requests at all, and the problem was on the clientside. so i wrote a little wrapper around my app to trigger
|
Beta Was this translation helpful? Give feedback.
I just encountered the same issue using Drizzle with the neon serverless connection. The caching docs do not go into detail into how to disable caching for Server Actions specifically but it seems using
cookies()
works.This 'magic' approach to caching at the cost of predictability really needs some work in my opinion.