Avoid modifying actual cache while recording optimistic transactions. #5484
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.
This is potentially an observable breaking change for code that accesses the real (as opposed to optimistic) cache during optimistic updates, rather than using the provided
proxy
object.Previously, the real
InMemoryCache
would also have itscache.data
andcache.optimisticData
properties temporarily updated to point to the new optimistic layer, so it would behave like theproxy
cache for the duration of the transaction. Now, only theproxy
object is updated, and the real cache is left untouched.If this change causes any problems, the most likely solution is to make sure optimistic update functions only access the provided
proxy
object, if they are expecting to read or write optimistic data. See the tests that were updated in this commit for examples of this correction.However, if the goal is to access non-optimistic data, using the real cache should now work more predictably than before, since the real cache is no longer modified during the transaction.
As a side benefit, we no longer need the
try
-finally
block inperformTransaction
, because theproxy
object can simply be forgotten once the transaction is done, so we no longer have to worry about resetting any temporarily modified properties of the real cache.