Server Action Caching
Unanswered
House Wren posted this in #help-forum
House WrenOP
I have a server action function such as:
that seems to be caching the call to
the console.log with the request_id is always the same, which indicates that that call is being cached.
how do I disable caching in this server action?
I already tried things like
any ideas? ðŸ™
thanks!
'use server'
...
export async function continueWithEmail(formData: FormData) {
const maybeEmail = formData.get('email');
const parseResult = z.string().email().safeParse(maybeEmail);
if (!parseResult.success) {
return parseResult.error.format();
}
const email = parseResult.data;
const result = await authClient.magicLinks.email.discovery.send({
email_address: email,
}); // 3rd party SDK
console.log('email resultId: ', result.response.request_id);
return redirect('/signup/continue-with-email/success');
}that seems to be caching the call to
authClient.magicLinks.email.discovery.send (this is probably using fetch behind the scenes but this is an SDK so I have no control over that fetch).the console.log with the request_id is always the same, which indicates that that call is being cached.
how do I disable caching in this server action?
I already tried things like
export const revalidate = 0 but nextjs complains that I can only export async functions from a server action file.any ideas? ðŸ™
thanks!
1 Reply
Willow shoot sawfly
// disable cache for this server action
const _cookies = cookies();
const _cookies = cookies();
export const getRecentAppointmentList = async () => {
try {
// disable cache for this server action
const _cookies = cookies();
const appointments = await databases.listDocuments(
DATABASE_ID as string,
APPOINTMENT_COLLECTION_ID as string,
[Query.orderDesc("$createdAt")]
);
const initialCounts = {
pending: 0,
cancelled: 0,
appointments: 0,
};
const counts = (appointments.documents as Appointment[]).reduce(
(acc: any, appointment: any) => {
if (appointment.status === "pending") {
acc.pending += 1;
} else if (appointment.status === "cancelled") {
acc.cancelled += 1;
} else {
acc.appointments += 1;
}
return acc;
},
initialCounts
);
const data = {
...counts,
totalCount: appointments.total,
documents: appointments.documents,
};
return parseStringify(data);
} catch (error) {
console.error(
"An error occurred while retrieving the appointments:",
error
);
}
};