Multiple apis update same cache & retrieval #1842
Replies: 2 comments 2 replies
-
all of these look like mutations to me - there should probably only be one query that reads the cart.
you never read from the cache directly when displaying something. The source of truth for the data is on the server - react-query is a “server state manager” after all. Please don’t write to the cache without also updating the backend. So when you display the cart, make a query that displays the carts data. |
Beta Was this translation helpful? Give feedback.
-
I have a similar question, but in my case multiple requests to modify the same query. Here's a simplified example:
and it's CRUD for each Object, e.g. during one phase multiple CREATE, UPDATE, and DELETE could happen triggering, e.g. 6 different queries that would modify the same |
Beta Was this translation helpful? Give feedback.
-
Ok, I'm hoping I can solve my need with react-query.
I have a few APIS that update the same object (cart), but since they are all different API's they have different cache keys.
ie..
// ALL OF THE FOLLOWING RETURN AN UPDATED "cart" Object. How do I reconcile this "cart" amongst the caches?
// Also, what mechanism can I use to "just read from the cache" ?
['addToCart', productId] <-- can happen on various product pages.
['addCoupon'']
['removeFromCart', productId]
These all update the "cart". But lets say I go to page that "displays" this page. There are no reasons to write on this page, just "read" from the cache. How can I read from the cache on the "cart". It seems since they all update "cart", I'd have to know what the last call was... This seems too complicated to always keep parity with the "cart" in cache, and then to just "read" it?
your thoughts?
Beta Was this translation helpful? Give feedback.
All reactions