RTK Query: Is there a way to find out cached queries parameters related to specific tag/id to help manual updating the cache??
See original GitHub issueI have understood that if you want to manually update cache you can do it with updateQueryData. You need the API endpoint parameters used in the query to update this specific response.
There are two problems I am facing here.
- I need the know the exact parameters used for this query to be able to manually update the response.
- There might be several different cached queries that should be updated.
When I update some item with useUpdateItemMutation, it gives the updated item as response. Now if I want to update the cache manually instead of invalidating the id to prevent unnecessary API calls it is hard to perform.
Whereas invalidating id can be done by giving the tag and id and all the cached queries related to that are handled.
My application has list of items (as responses for searches with different kind of query parameters) and the same item can be in many of them. When I am performing the update I would need to make sure that the item is updated to all lists where it is.
I don’t know if this is possible without invalidating?
I understand that RTK Query is not normalized and therefore I cannot update the tag/id directly but could it be possible to add a way to get all cached API calls (including used parameters) related to spesific tag/id? Then I could manually update the caches everywhere when needed.
This issue is related to this https://github.com/reduxjs/redux-toolkit/issues/1529#issuecomment-923005215
EDIT: Just noticed RTKQ uses the query name for the
updateQueryData
call, although it uses tags for query invalidation. react-query uses the equivalent of tags for all of these operations. I wonder if theinvalidatesTags
array could also just use the query name. Or alternatively ifupdateQueryData
could just use tags. Anyway, this is a totally different conversation. I was just kind of thinking out loud. I suppose it’s likely there are limitations that prevent this sort of thing.
Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (6 by maintainers)
Sure, that would be very welcome! Make yourself a fork of this repository and start editing the documentation over in the
/docs/rtk-query
folder.You don’t even need to check it out locally for the most part - just press the
.
key on your keyboard once you are in your fork.Once you’re done, create a PR from your fork 😃
@dutzi RTK Query is per design not a normalized cache, it’s a document cache. There is no recommended way to do that with it - it’s just not a design goal.