NerdWalletOSS / apollo-cache-policies

An extension of the Apollo 3 cache with support for advanced cache policies.
Apache License 2.0
156 stars 22 forks source link

Do not evaluate read policies for missing entities #11

Closed danReynolds closed 3 years ago

danReynolds commented 3 years ago

Resolves issue outlined in https://github.com/NerdWalletOSS/apollo-invalidation-policies/issues/2. Thanks to @maury91 and @hwhh for pointing out this issue. I first hadn't been able to repro but the point from @hwhh recently that it occurs for non-normalized entities with different store field names helped me repro it.

The issue was that if you have read eviction policies enabled using the timeToLive config and are fetching a field with particular variables that is not currently in the cache, but that same field is already in the cache with different variables, then it would error out because the cache will try and diff that entity as part of a cache-and-network style query to get the current value, triggering a read policy check for an entity that isn't yet present. Later when it comes back from the network it gets written into the cache and will have a time to live, but in the case where it first is diff'd and is not present we should just abort trying to run a read policy on an entity that isn't in the cache altogether.