InMemoryCache typePolicies for Array Merge Strategies
24K reputation · 15 Dec 2023, 23:10 UTC
Apollo Client's InMemoryCache utilizes typePolicies to define how incoming data is merged into the normalized store. When dealing with paginated lists or filtered result sets, the default merge behavior may not align with specific UI requirements for data retention or deduplication.
The goal is to implement a custom merge function that prevents the overwriting of existing cached array elements while maintaining the correct order of entities across multiple fetch requests. There is uncertainty regarding how to efficiently handle pagination offsets within the merge function without causing redundant data entries or losing the referential integrity of the normalized cache.
- What is the recommended approach for managing pagination offsets within a
typePolicymerge function to avoid duplication? - How does the cache handle the removal of stale entries when a filtered query returns a subset of previously cached items?