#How can I invalidate TanStack Query cache for all users after updating a post?

3 messages · Page 1 of 1 (latest)

wheat kite
#

I’m using TanStack Query in my app to cache posts and post details on the client side.

When a user updates a post, I can call "queryClient.invalidateQueries()" to invalidate the cache for the current user

However, this only affects the current user’s browser/session.

What I want to understand is: how can I make sure that other users who are currently using the app also get the updated post data?

For example:

  1. User A updates a post.
  2. The server saves the update.
  3. User B, who already has the posts cached in their browser, should see the updated data too.

Does TanStack Query provide a way to invalidate cache across all users, or do I need to implement something like WebSocket/SSE to notify each client and then call "invalidateQueries()" locally?

quartz wind
#

You cannot. A client can only invalidate their own cache

#

The server has to notify the client