Next.js Discord

Discord Forum

Cache and revalidation setup with the App router

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
I am in a situation where I have several options in my cache and revalidation setup which all have their serious drawbacks, so I am reaching out for help here to see if I am missing something, am I not using some features properly, or missing a different options which would work for my case.

I have a combination od revalidate path and tag calls from our external CMS to a custom endpoint on next.js which does the revalidation and it all works perfectly except one major detail, we exceed our monthly cache writes almost in a day.

The source of our increased cache writes and with that the increased monthly bills, is an endpoint which receives a bunch of different query params to filter the actual list that gets returned and the response is a bit large in itself, so it all adds up fairly quickly, I end up writing a lot of cache for unique query param combinations that are not even that likely to be reused by other visits having their own searches (If they are reused often enough I would expect to see the amount of data cache written falling, but its mostly consistent day to day)

This is where my dilemma starts, if I turn off caching for that particular endpoint then almost none of my pages can be static, cause most of them use the endpoint in question and that is a serious performance drawback. If I just keep it as it is the monthly bill just for that data cache would be around $200 and I don't get to do incremental static regeneration cause that uses the same billing metric, not to mention that future scaling plans don't seem plausible with this setup.

One thing that I tried to do is to swap out fetch with axios for that one endpoint, which results in skipping the cache writes for that endpoint while still allowing my pages to be static, but doing so breaks my ability to revalidate on demand, so that doesn't work either.

Really lost on what to do here, would highly appreciate any hint in a direction of solving this.

0 Replies