Skip to content

Commit

Permalink
🐛 Refactor HashMapLoadingCache.getLoading() to prevent double get() c…
Browse files Browse the repository at this point in the history
…alls and reduce race conditions
  • Loading branch information
ujibang committed May 14, 2024
1 parent d734166 commit cbf7113
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ public Optional<V> remove(K key) {

@Override
public Optional<V> getLoading(K key) {
if(get(key) != null) {
return get(key);
var cachedValue = get(key);

if(cachedValue != null) {
return cachedValue;
} else {
var value = Optional.ofNullable(loader.apply(key));

Expand Down

0 comments on commit cbf7113

Please sign in to comment.