Stale data persistence in cache-first fetch policy
0 reputation · 08 Dec 2022, 16:40 UTC
Apollo Client Cache Consistency
When utilizing the cache-first fetch policy, Apollo Client prioritizes the local store and bypasses network requests if the query is fully satisfied by existing data. This behavior ensures performance but introduces challenges regarding data freshness when the server state changes independently of the client.
A specific concern arises during partial cache updates. While the normalization process flattens objects with unique IDs, updates to arrays or lists often do not trigger automatic updates across all dependent queries unless manual cache manipulation is performed via cache.modify.
Given these constraints, how does the client distinguish between a fully satisfied cache and one containing stale data without triggering a network request? Is there a documented mechanism to implement a stale-while-revalidating pattern within the cache-first policy to ensure UI consistency?