T
TanStack7mo ago
stormy-gold

Keeping data up-to-date with cross user shared data

Consider a scenario where data on a page is shared between multiple users (say User A and User B). Assuming a stale time of 5 minutes for the query to fetch that data. If User B has updated the data and User A tries to access the data before the stale time expires, User A will see outdated data. Is there a way to handle this situation while still having the cache included? Preferably without referchInterval and refetchOnFocus
4 Replies
genetic-orange
genetic-orange7mo ago
when you "update data", it usually happens with a mutation to update it on the server, and that's why you usually invalidate the cache entry with invalidateQueries after a mutation
stormy-gold
stormy-goldOP7mo ago
You are right, but that will only invalidate query for the user who has mutated the data.. How will other users who are using the same data get the updated data? They will only get the updated data when their stale time is expired and the query is refetched.. But until then they will see cached data which will be outdated..
genetic-orange
genetic-orange7mo ago
Do you mean with "other user" someone on a different computer? seems like you want websockets or server-sent events
stormy-gold
stormy-goldOP7mo ago
yes on another computer or a different login...

Did you find this page helpful?