Invalidate next.js cache externally
Answered
Siberian posted this in #help-forum
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?
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
4 Replies
Asian black bear
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
@Asian black bear is there an example repo for this?
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 😛