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

Avoid modifying actual cache while recording optimistic transactions. #5484

Merged
merged 2 commits into from
Oct 21, 2019

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Oct 21, 2019

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 its cache.data and cache.optimisticData properties temporarily updated to point to the new optimistic layer, so it would behave like the proxy cache for the duration of the transaction. Now, only the proxy 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 in performTransaction, because the proxy 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.

This is potentially an observable breaking change for code that accesses
the real cache during optimistic updates, rather than using the provided
proxy object.

Previously, the real InMemoryCache would also have its cache.data and
cache.optimisticData properties temporarily updated to point to the new
optimistic layer, so it would behave like the proxy cache for the duration
of the transaction. Now, only the proxy 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 in
performTransaction, because the proxy 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.
@benjamn benjamn merged commit 2ec10b9 into release-3.0 Oct 21, 2019
@benjamn benjamn deleted the revamp-optimistic-cache-transactions branch October 21, 2019 23:48
benjamn added a commit that referenced this pull request Feb 21, 2020
This essentially undoes #5484, so that reactive variables (which have
access to the InMemoryCache object but know nothing about proxy objects)
can benefit from transactional broadcast batching when calling
cache.broadcastWatches().
@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.

1 participant