Next.js Discord

Discord Forum

Invalidate next.js cache externally

Answered
Siberian posted this in #help-forum
Open in Discord
Avatar
SiberianOP
Using next.js 14 with the app directory

We have an app where we make a couple of calls (which we also cache) to a database. We have another package that constantly updates the db data based on certain events.

What would be the best way to revalidate the data when the package updates the db?
Answered by Asian black bear
Call a public route handler that you secure using a secret token. The route handler then just calls revalidatePath/Tag
View full answer

4 Replies

Avatar
Asian black bear
Call a public route handler that you secure using a secret token. The route handler then just calls revalidatePath/Tag
Answer
Avatar
SiberianOP
thank you!
Avatar
SiberianOP
@Asian black bear is there an example repo for this?
Avatar
Asian black bear
What for? It's just a simple POST route handler that should check the header for a token and then call the revalidation functions. That's basically 5 lines of code 😛