Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTK Query] Option to invalidate cache but not refetch until the next time data is fetched #4817

Open
Tasin5541 opened this issue Jan 16, 2025 · 0 comments

Comments

@Tasin5541
Copy link

There are multiple scenarios where we want to invalidate the cached data so that the next time we need the data, it's fetched from server but we don't need the new data just yet.

Scenario 1:
On an edit form, we fetch the current data, make edits, then save and go back to the previous screen. This save invalidates the cache for the current data and refetches it again (but we don't need the new data yet because we are going back to the previous screen).

Scenario 2:
Consider a table with pagination and multiple filters. There are actions for each row on the table. One such action can remove all the rows from the current page. If user is currently on the last page and removes all rows, we have to invalidate the cache which triggers a refetch but there is no data for that page anymore. We manually set the page to 1 after the action which triggers another refetch and this time there is data. So, basically 2 api calls going out, once through cache invalidation on mutation and then again after search parameters reset.

We are currently handling scenario 1 by always refetching on mount and not invalidating any tags on mutation. This ensures we have fresh data every time but at the same time, we're not getting the benefit of caching. We could not find any solution for scenario 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant