NextJS 13/14 Cache works globally, per session or how?
Unanswered
Polish posted this in #help-forum
PolishOP
Will revalidate path/tag issue a refetch to update the info for all users on all web browser’s sessions?
In an authenticated scenario were users only see their orders, Let’s say after a server action I want to revalidate the /orders path so this user could see the new order created. Will this also trigger a request to update the same path on all other users even when they have not added anything new?
In an authenticated scenario were users only see their orders, Let’s say after a server action I want to revalidate the /orders path so this user could see the new order created. Will this also trigger a request to update the same path on all other users even when they have not added anything new?
9 Replies
Short answer: path, tags are mainly relevant for the global, server-side cache
This is especially useful to rerender static pages on demand
usually, your orders page should be dynamic
a page is a good fit to be static if:
- it doesn't move too much (that's your case)
- it's the same for at least a group of user (same language, tenant, theme... or even same for everybody) => that's not your case
- it doesn't move too much (that's your case)
- it's the same for at least a group of user (same language, tenant, theme... or even same for everybody) => that's not your case
if you have few users that could be worth it though, depends on your use case. Be careful to secure the access to those pages though via a middleware or smth alike (this need for security also makes dynamic rendering easier to setup, eventhough it doesn't automatically imply dropping static).
Regarding invalidating for all users, you may want to have the userId as a dynamic params
so you can invalidate "42/orders" for instance
(in older versions of Next a bug prevented that but it should be ok with 13.4+ or 14)