question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

I 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.

  1. I need the know the exact parameters used for this query to be able to manually update the response.
  2. 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 the invalidatesTags array could also just use the query name. Or alternatively if updateQueryData 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:open
  • Created 9 months ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
phryneascommented, Dec 9, 2022

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 😃

1reaction
phryneascommented, Dec 17, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cache Behavior - Redux Toolkit
RTK Query provides a number of concepts and tools to manipulate the cache behaviour and adjust it to your needs.
Read more >
RTQK: Better manual cache updates or clearer info ... - GitHub
RTK Query : Is there a way to find out cached queries parameters related to specific tag/id to help manual updating the cache??...
Read more >
RTK Query cache - Stack Overflow
Tags are not for caching, but for invalidation. So yes, queries (and to a certain extent, mutations) will be cached independently if you...
Read more >
Frontend Caching with Redux Toolkit Query - Bits and Pieces
RTK Query is a powerful server data caching solution explicitly built ... So, let's see how we can fetch and cache data using...
Read more >
RTK Query Best Practices - Medium
In June 2021, Redux Toolkit introduced a powerful tool for data fetching and caching called RTK Query. Compared to popular alternatives like React-Query, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found