Skip to content

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

Closed as not planned
@Tasin5541

Description

@Tasin5541

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions