Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invalidate server-action cache?

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.

like image 540
Luc Gagan Avatar asked Mar 23 '26 01:03

Luc Gagan


1 Answers

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.

like image 107
Vu Tran Avatar answered Mar 26 '26 13:03

Vu Tran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!