-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
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.
this.lastWrite = { | ||
result, | ||
variables: options.variables, | ||
evictCount: cacheEvictCounts.get(this.cache), | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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 publicApolloCache
API to support any new functionality. If we identify any other potential consumers of this information, we might consider a more official API.