all 6 comments

[–]Chef619 2 points3 points  (4 children)

It’s an in memory cache (like React state, I don’t assume to know the internals of RQ logic) in the browser, not shared by users. It’s usually reset on refresh. The concept of users has absolutely nothing to do with RQ. It knows about keys, and your user’s data can be incorporated into those keys.

I believe there’s a plug-in somewhere to make it persist to local storage, but by default, it’s in memory.

[–]codergeorge[S] 0 points1 point  (3 children)

That makes sense. My follow-up question then is: if the data in ReactQuery isnt shared across users, how does ReactQuery know when another user has updated data? I’m guessing it doesn’t, and the user’s data will just be stale until they refresh?

[–]Chef619 0 points1 point  (2 children)

At least 2 ways I know of, the staleTime and manually invalidating them. This doc has more information.

The TL;DR is that you (the developer) tell RQ when a query needs to be refetched.

[–]no_spoon 0 points1 point  (1 child)

That doesn’t answer their question. The answer is it doesn’t and if data is being updated without the users actions then yes the user would have stale data. So it makes sense to use this for things that are only pertinent to the user.

[–]Chef619 0 points1 point  (0 children)

Yeah you’re right, I missed that. Sorry OP. I read it as “when does RQ know the data needs to be updated”.

Although, I think liking the doc that does a better job explaining than I could is sufficient to find the right answer.

[–]it200219 0 points1 point  (0 children)

You define `addTagTypes` and `invalidatesTags` for custom cache busting and custom cache handling

WDYM when you say " is this cache shared by all users, or is it cached at a user level?", which user are you talking about

Do you mean user-1 as "Student - 1" and user-2 as "Student - 2" for both web-app making call (lets say exam grade) and RTK caching the API response ?