computeIfAbsent method added to AbstractCacheMap

pull/6222/head
Nikita Koksharov 4 months ago
parent 3b074a28de
commit 1175df2237

@ -22,6 +22,8 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import java.util.function.Function;
/** /**
* *
@ -537,4 +539,17 @@ public abstract class AbstractCacheMap<K, V> implements Cache<K, V> {
}); });
return result.get(); return result.get();
} }
@Override
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
AtomicReference<V> result = new AtomicReference<>();
map.computeIfAbsent(key, k -> {
V value = mappingFunction.apply(k);
result.set(value);
CachedValue<K, V> entry = create(key, value, timeToLiveInMillis, maxIdleInMillis);
return entry;
});
return result.get();
}
} }

Loading…
Cancel
Save