-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Values currently being loaded shows up as null
entries in synchronous().asMap()
#1626
Comments
I think this is correct in behavior and documentation, but I understand its a little confusing. The aggregated calls like caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java Lines 175 to 184 in 5d453e9
Perhaps the The synchronous view would be not present in the same way that an in-flight load for |
I see those inaccuracies as just being slightly out of date. With loading entries, you can have a sequence of observed events like this:
which shouldn't be possible to observe unless an entry was inserted and then removed. It's also especially inaccurate if the loading entry ends up being cancelled for whatever reason. If that happened, the entry shouldn't have been observable at any point. It's not just observing an out-of-date state of the cache in that case. |
If you're asking for If you are asking for the size, isEmpty, or other aggregated methods to mask it then I think that will be problematic. If we maintain our own size counter outside of |
Right, I don't think it needs to be atomically accurate. It can be slightly out of date like how evictions and invalidations are handled.
I agree it has to be best effort, but I don't see why it can't be linearizable. |
Being linearizable can be a good or bad characteristic, because it forces certain atomicity in visible state. A |
I think I'm only asking for sequential consistency and not linearizability. Let's say you start loading an entry, but it gets cancelled before it's finished. You shouldn't be able to see the map as being non-empty at any point, since that never happens from the synchronous view of the cache. I think these inaccuracies should be tolerated in the
but not these
|
Maybe you can enumerate the changes you'd like to see? Right now |
For
Let's say we have a
Basically, I just want the documentation on
You meant to say that right now it's returning Interestingly, right now |
Sorry, yes I agree with the I think only key-based operations should be strict and only allow a successfully completed future value to be treated as present. A loading, failed, or future holding a null value should be treated as absent. So I disagree with size / isEmpty as they cross-cut multiple entries. That is already going to be inconsistent with the iterator for other reasons. Improvements to the documentation are always worthwhile and any suggestions would of course be welcome. |
fixes #1626) The keySet and its iterator will now suppress in-flight entries for the contains test and by its iterator. The retain and removal methods will discard in-flight mappings, like the entrySet view does. This is intentional as it is better to overly discard data then keep stale contents due to incorrect linearization assumptions (of which async can offer few). The synchronous views are best-effort, lenient, and try to match a user's likely expected or intended behavior while being conservative by being cautiously safe. Thus, small leaks of in-flight behavior is preferrable, especially given the concurrent nature of the use-case, and we encourage using the async asMap view when orchastrating more nuanced behavior.
#1626) The keySet and its iterator will now suppress in-flight entries for the contains test and by its iterator. The retain and removal methods will discard in-flight mappings, like the entrySet view does. This is intentional as it is better to overly discard data then keep stale contents due to incorrect linearization assumptions (of which async can offer few). The synchronous views are best-effort, lenient, and try to match a user's likely expected or intended behavior while being conservative by being cautiously safe. Thus, small leaks of in-flight behavior is preferrable, especially given the concurrent nature of the use-case, and we encourage using the async asMap view when orchastrating more nuanced behavior.
"A mapping is not present if the value is currently being loaded" according to
caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java
Lines 191 to 192 in 5d453e9
This might be an intentional design choice, but a mapping that is "not present" is not the same as being mapped to
null
(with regard tocontainsKey
,size()
, etc), so this documentation is inconsistent with the actual behaviors ofsynchronous().asMap()
.Here's a test case demonstrating this:
The text was updated successfully, but these errors were encountered: