Next.js Discord

Discord Forum

How to programmatically clear all caches in the pages router?

Unanswered
Spectacled Caiman posted this in #help-forum
Open in Discord
Spectacled CaimanOP
I'm currently working on connecting a Nextjs application with a CMS. Layouts and Elements come from the CMS as json. Nextjs then dynamically puts the page together. I do this by using a optional catchall route in the root of the pages directory and using the slug I get to query the CMS in getStaticProps and work from there. I currently don't use getStaticPaths since nextjs already handles caching on first load for me.

The problem i have is that when changes are made in the CMS the cache needs to be revalidated. This isn't an issue for single pages, but I haven't found a way revalidate everything when the Cache in CMS is cleared.
revalidateTag() seems to be limited to the app router (I'm using pages). If it weren't I could simply tag the request in getStaticProps and clear them all.

The only solution I could think of is to get the Sitemap from the CMS and call revalidate on every single slug. However, that seems pretty bad.
I've already created a branch and ported everything to the app router, but it's not fast enough.

Anyone ever come across a similar Problem?

0 Replies