Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable feud-stopping logic after any cache eviction. #6817

Merged
merged 2 commits into from
Aug 10, 2020

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Aug 10, 2020

When application code evicts an object or its fields from the cache, and those evictions trigger network requests, the network data is often vital for repairing the damage done by the eviction, even if the network data look exactly the same as the previously-written data.

In other words, after any cache eviction, we should disable the logic introduced in PR #6448 to stop query feuds. This exception is reasonable because feuding queries only write additional data into the cache, rather than evicting anything, so we can safely assume evictions do not contribute to a cycle of competing cache updates.

I freely admit the method of counting evictions that I've implemented here is a bit of a hack, but it works for any ApolloCache implementation, without requiring the public ApolloCache API to support any new functionality. If we identify any other potential consumers of this information, we might consider a more official API.

When application code evicts an object or its fields from the cache, and
those evictions trigger network requests, the network data is often vital
for repairing the damage done by the eviction, even if the network data
look exactly the same as the previously-written data.

In other words, after any cache eviction, we should disable the logic
introduced in PR #6448 to stop query feuds. This exception is reasonable
because feuding queries only write additional data into the cache, rather
than evicting anything, so we can safely assume evictions do not
contribute to a cycle of competing cache updates.

I freely admit the method of counting evictions that I've implemented here
is a bit of a hack, but it works for any ApolloCache implementation,
without requiring the public ApolloCache API to support any new
functionality. If we identify any other potential consumers of this
information, we might consider a more official API.
Comment on lines +290 to +294
this.lastWrite = {
result,
variables: options.variables,
evictCount: cacheEvictCounts.get(this.cache),
};
Copy link
Member Author

@benjamn benjamn Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to throw away this.lastWrite after a certain time (thus setting a limit on how long the feud-stopping logic matters), that would also be pretty easy to implement:

setTimeout(() => {
  this.lastWrite = void 0;
}, 10000);

This would mean: if more than 10 seconds have passed, any new data from the network gets written into the cache unconditionally, even if it's the same as the previously-written data.

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @benjamn, and I agree with regards to holding off on making this an official part of the ApolloCache API.

@benjamn benjamn merged commit 46dd608 into release-3.2 Aug 10, 2020
@benjamn benjamn deleted the skip-feud-logic-after-eviction branch August 10, 2020 18:51
hwillson pushed a commit that referenced this pull request Aug 21, 2020
When application code evicts an object or its fields from the cache, and
those evictions trigger network requests, the network data is often vital
for repairing the damage done by the eviction, even if the network data
look exactly the same as the previously-written data.

In other words, after any cache eviction, we should disable the logic
introduced in PR #6448 to stop query feuds. This exception is reasonable
because feuding queries only write additional data into the cache, rather
than evicting anything, so we can safely assume evictions do not
contribute to a cycle of competing cache updates.

I freely admit the method of counting evictions that I've implemented here
is a bit of a hack, but it works for any ApolloCache implementation,
without requiring the public ApolloCache API to support any new
functionality. If we identify any other potential consumers of this
information, we might consider a more official API.
@benjamn benjamn mentioned this pull request Aug 21, 2020
11 tasks
benjamn added a commit that referenced this pull request Aug 25, 2020
benjamn added a commit that referenced this pull request Aug 25, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants