Allow manually associating caches with reactive variables. #7350
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the context of a larger cache read operation, accessing a reactive variable automatically associates the variable with the cache, so future updates to the variable can be broadcast to the cache.
Outside this context, it may not be possible for the variable to discover the currently active cache. For example, there is no currently active cache in asynchronous
ApolloLink
code (#7338).Since we recently added a
reactiveVar.forgetCache(cache)
method in #7279, I think it makes sense to have a manual way to do the opposite, which I have decided to callreactiveVar.attachCache(cache)
.Although this attachment is manual at the moment, in a hypothetical future where the client/cache manage the persistence of reactive variables, it should be easy to attach the appropriate cache to those variables when they are first initialized, which would enable reactive updates from literally anywhere, with no additional effort by the developer.