How to limit unused cache size (instead of time) for given endpoint? #2948
Unanswered
pasieronen
asked this question in
Q&A
Replies: 1 comment
-
RTK has docs on handling this manual cache manipulation : - And maybe this is what you are looking for: - When you unmount the component, you can call the |
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.
-
One part of my app has a search box + result list. The search box remembers the previous search when you navigate elsewhere in the app (unmounting this part) and later return.
The queries to the server are very slow, so setting "keepUnusedDataFor" to a large value (say, 5-10 minutes) would avoid refetching (and showing a loading spinner to user) when the user returns to this part of the app (which happens quite often).
However, the responses can be large (megabytes), and in some cases the user might do lots of them, so keeping all responses for 5-10 minutes is not possible (too much memory used).
Can I somehow convince RTK to keep only the latest result (or last N results) for unused subscriptions for this endpoint?
Something like a per-endpoint "maxUnusedData: 2" setting would be ideal... but perhaps there's something I could do in e.g. onCacheEntryAdded to get similar effect? (manually dispatch something maybe - but what?)
(A similar question was asked earlier in #2113, but it doesn't really solve my problem)
Beta Was this translation helpful? Give feedback.
All reactions