Next.js Discord

Discord Forum

Invalidate next.js cache externally

Answered
Siberian posted this in #help-forum
Open in Discord
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 Giant panda
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

Giant panda
Call a public route handler that you secure using a secret token. The route handler then just calls revalidatePath/Tag
Answer
SiberianOP
thank you!
SiberianOP
@Giant panda is there an example repo for this?
Giant panda
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 😛