computeIfAbsent method added to AbstractCacheMap

pull/6222/head
Nikita Koksharov
parent 1175df2237
commit d8c2c58f26

@ -542,14 +542,15 @@ public abstract class AbstractCacheMap<K, V> implements Cache<K, V> {
@Override
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
AtomicReference<V> result = new AtomicReference<>();
map.computeIfAbsent(key, k -> {
CachedValue<K, V> v = 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();
if (v != null) {
return v.getValue();
}
return null;
}
}

Loading…
Cancel
Save