-
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
Unnecessary fetches when using asynchronous bulk load #1409
Comments
I think it would be fine to reorder those lines or await on the |
It would be great if behavior could generally be changed to guarantee completion. |
…l keys to be added to the cache before returning requested keys Fixes ben-manes#1409.
I ran into the same issue and thought I'd try my hand at the refinement with #1550. |
Thanks! I'll take a look. There are a few things that I want to review while we're looking at this functionality.
I think your test case change was for 1. Offhand I don't recall if 2 & 3 were handled very well presently. |
For a cache backed by AsyncCacheLoader that
Observed behavior:
Depending on timing, asyncLoadAll() may sometimes be called unnecessarily for already pre-fetched items.
A reproducer can be provided if needed (that injects artificial delays in the map returned by asyncLoadAll()).
The following notes on LocalAsyncCache should however explain the behavior:
https://github.com/ben-manes/caffeine/blob/v3.1.8/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java#L149
https://github.com/ben-manes/caffeine/blob/v3.1.8/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java#L260
The above results in behavior subject to timing between completion of addNewEntries(result) and when the next getAll() is triggered.
If getAll() is triggered again after the Future returned by a previous getAll() completed, but before "pre-fetched" items are added to the cache by addNewEntries(result), then the second call of getAll() could re-trigger a fetch of items that were already fetched (but not yet added to the cache.
Assumption is that getAll() completion immediately after requested items are added to the cache (by
fillProxies(result)
) is an optimization.For a scenario where asyncLoadAll() might be very expensive (as it is in my use case), this optimization is not the appropriate trade-off.
Question:
Would it be possible to add an option that allows completion of getAll() only after all fetched items have been added to the cache?
The effect of this should be the same as swapping the order of
fillProxies(result);
andaddNewEntries(result);
in AsyncBulkCompleter.The text was updated successfully, but these errors were encountered: