completely remove guava related classes and use caffeine backed cache#207
Merged
Conversation
Replace computeIfAbsent-based load coalescing with an external ConcurrentHashMap<K, CompletableFuture<V>> in-flight map. Previous approach use user-supplied loader inside the ConcurrentHashMap mapping function, which holds a bin-level lock during computation. This has two problems for a general-purpose cache API: - A slow loader blocks all map operations for keys in the same bin - A loader that calls back into the same cache can deadlock on ConcurrentHashMap The new approach: 1. Atomically putIfAbsent a CompletableFuture into the in-flight map 2. The winning thread runs the loader with no locks held 3. Losing threads join() the existing future 4. CompletionException is unwrapped so all callers see the same exception type regardless of whether they were the loader or waiter 5. remove(key, fresh) in finally ensures only the owning future is cleaned up, preventing accidental clobber of a concurrent reload Coalescing semantics are preserved: concurrent cold misses for the same key still trigger exactly one loader invocation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.