Fixed - fixed possible race-condition in RMapCache.computeIfAbsent() method

pull/6287/head
Nikita Koksharov 3 months ago
parent 9aaf0a2f85
commit ee34f81c18

@ -146,7 +146,10 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
if (value == null) {
V newValue = mappingFunction.apply(key);
if (newValue != null) {
fastPut(key, newValue, ttl.toMillis(), TimeUnit.MILLISECONDS);
V r = putIfAbsent(key, newValue, ttl.toMillis(), TimeUnit.MILLISECONDS);
if (r != null) {
return r;
}
return newValue;
}
return null;
@ -177,7 +180,12 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
return CompletableFuture.supplyAsync(() -> mappingFunction.apply(key), getServiceManager().getExecutor())
.thenCompose(newValue -> {
if (newValue != null) {
return fastPutAsync(key, newValue, ttl.toMillis(), TimeUnit.MILLISECONDS).thenApply(rr -> newValue);
return putIfAbsentAsync(key, newValue, ttl.toMillis(), TimeUnit.MILLISECONDS).thenApply(rr -> {
if (rr != null) {
return rr;
}
return newValue;
});
}
return CompletableFuture.completedFuture(null);
});

Loading…
Cancel
Save