Skip to content

completely remove guava related classes and use caffeine backed cache#207

Merged
xsalefter merged 25 commits into
java2xfrom
guava-removal
Jun 5, 2026
Merged

completely remove guava related classes and use caffeine backed cache#207
xsalefter merged 25 commits into
java2xfrom
guava-removal

Conversation

@xsalefter

Copy link
Copy Markdown
Contributor

No description provided.

xsalefter added 25 commits May 27, 2026 02:51
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.
@xsalefter xsalefter merged commit 3eeec5e into java2x Jun 5, 2026
12 of 14 checks passed
@xsalefter xsalefter deleted the guava-removal branch June 5, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant