CreateEntityAdapter Pagination: Missing Automatic Page Eviction
0 reputation · 28 Aug 2024, 03:23 UTC
Goal
When paging through a large dataset with Redux Toolkit’s createEntityAdapter, the store keeps every fetched entity. The adapter’s API exposes removeAll and removeOne, but it lacks a built‑in mechanism to automatically drop entities that fall outside a desired window of pages.
Constraints
• The adapter normalizes data into an ids array and an entityMap object, so the memory footprint grows linearly with the number of fetched pages.
• Pagination metadata can be stored in a pageInfo field, but the adapter does not enforce any size limit or eviction policy.
• Developers must decide how to prune old pages (e.g., LRU, fixed window, or manual cleanup) without affecting other UI components that might still reference those entities.
Unresolved Decision
Which strategy should be integrated into the slice’s reducer or thunk logic to keep the store bounded while maintaining consistent pagination behavior?
Questions
- What patterns exist for implementing a sliding‑window eviction policy within a
createEntityAdapterslice? - How can we ensure that evicted entities are not inadvertently referenced by other parts of the application?
- Would a middleware or custom selector provide a cleaner separation of eviction logic from reducer code?