Next.js Discord

Discord Forum

Understanding caching in next js 14

Unanswered
Black Vulture posted this in #help-forum
Open in Discord
Black VultureOP
I have a question about caching in next js 14.
Before I get to the question, I will briefly describe my application. It is a customer portal for a large fitness studio chain, where you can book and view courses, statistics etc. The data is stored in an existing external ERP system, which can be accessed via an API.
My API calls happen in server actions. The API call is made via fetch and as an additional option I pass the next object, in which I have the revalidate and the revalidateTag. Each user has their own account and the login happens via next auth.

As soon as I set the revalidate to a number greater than 0, a cache on the next js page (vercel) also appears to be present. If another user logs in, then different values should be visible, e.g. in the transaction history, and the same cache should not be used. This also seems to be the case for server actions. Can you please briefly explain why this is the case? Do you hash certain data and check this?

If I create a route (GET) instead of a server action and then call this route with revalidate=60, then this value is the same for all users. Apparently the same cache is used here.

For me it is only important that a user does not suddenly see data from other users because they are in the cache. 
Do I have to include the userId in the revalidateTag to ensure this? If so, when does the cache on the vercel side overflow? If I have e.g. 10,000 users and there are e.g. 7 tags, then there would be 70000 cached values. Are values then automatically deleted, similar to a queue?

The following question also arises in this context: If I don't include the user id in the revalidate tag, will the global cache be updated every time a user triggers a certain action? If there are a lot of active users, it would be as if there was no cache, as it would be revalidated every time.

I look forward to your reply

0 Replies