Managing memory overhead during RTK Query cache invalidation
0 reputation · 29 Dec 2021, 10:48 UTC
Redux Toolkit Query (RTK Query) uses a tag-based system via providesTags and invalidatesTags to automate the synchronization of server-side state with the local store. While this prevents stale data, the global store continues to hold cached entries until they are explicitly removed or the subscription expires.
In applications handling large datasets or frequent updates, there is a tension between maintaining a responsive cache and managing the memory overhead of the Redux store. Relying solely on automated invalidation ensures data freshness but does not inherently prune the store of unused or legacy entries that are no longer active in the UI.
Which strategies are most effective for balancing memory usage with cache persistence in RTK Query? Does the keepUnusedDataFor configuration provide sufficient granularity for high-frequency updates, or is manual state pruning required to prevent memory leaks in long-running sessions?