Next.js Discord

Discord Forum

Caching rarely updated data

Unanswered
Large oak-apple gall posted this in #help-forum
Open in Discord
Large oak-apple gallOP
I want to cahce responses from api (kind of calendar). They are rarely (never) changed, but become irrelevant with each passing day (no need to look into past).

What I considered:
- get monthly data and cache on client. Bad solution since every site visitor will still initiate request to api
- get monthly data and cache on server. Decent solution, but without server restarts this cache will pile up even if it is already outdated (month ended). As far as I found, there is no way to simply purge cache, only revalidate

Is there any better approach for this?

Ideal solution: cache month, erase cache on first day of next month.

1 Reply

Large oak-apple gallOP
I asked v0 this question and it gave reference to mysterious unstable_expireTag, but this link redirects to revalidateTag, which is not erasing cache completely, but updating it
https://nextjs.org/docs/app/api-reference/functions/unstable_expireTag