Replies: 1 comment
-
|
RTK Query doesn’t expose a “delete this one cache entry” API on purpose. Cache entries are owned by the RTKQ reducer, and you’re not supposed to surgically remove arbitrary That said, you have a couple of supported options depending on what you actually want:
endpoints: (build) => ({
getThing: build.query<Thing, Args>({
query: (args) => ({ url: "...", params: args }),
keepUnusedDataFor: 0, // or a small number
}),
})That makes “inactive” queries disappear essentially immediately after the last component unsubscribes, which matches the “don’t reuse” intent without custom purging logic.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have created a utility function to update the query cache based on some patch function. I want this utility function to do the following:
This function is used when doing optimistic updates: instantly update all active queries with some patch function and purge the inactive queries for that endpoint so they won't be re-used in the future.
However, I haven't found a way to purge cache entries manually from the state. I don't want to invalidate tags because that causes a refetch of all the active queries as well which makes no sense cause we are optimistically updating those already. Is there a way to purge specific queries from the cache? Or do you see a better approach to what I am trying to do?
The utility function is a work in progress but looks something like this:
Beta Was this translation helpful? Give feedback.
All reactions