I cannot wrap my head around how to invalidate server action cache.
Next.js documentation mentions revalidatePath and revalidateTag, but I don't see what's the relationship with the server-action.
My server-action is in a separate file called suggestOutline, which exports function suggestOutline, and I just call it from useEffect(), e.g.
useEffect(() => {
suggestOutline();
});
but past the first request, the data returned is always cached data.
This is example from their doc: https://nextjs.org/docs/app/api-reference/functions/revalidatePath#server-action
'use server'
import { revalidatePath } from 'next/cache'
export default async function submit() {
await submitForm()
revalidatePath('/')
}
Simply speaking, request to the server action from that the defined path will be invalidated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With