diff --git a/core/src/main/java/org/elasticsearch/common/cache/Cache.java b/core/src/main/java/org/elasticsearch/common/cache/Cache.java index 3f4177ecc50..aac8a7d4792 100644 --- a/core/src/main/java/org/elasticsearch/common/cache/Cache.java +++ b/core/src/main/java/org/elasticsearch/common/cache/Cache.java @@ -257,7 +257,10 @@ public class Cache { * @return the value to which the specified key is mapped, or null if this map contains no mapping for the key */ public V get(K key) { - long now = now(); + return get(key, now()); + } + + private V get(K key, long now) { CacheSegment segment = getCacheSegment(key); Entry entry = segment.get(key, now); if (entry == null || isExpired(entry, now)) { @@ -279,11 +282,11 @@ public class Cache { */ public V computeIfAbsent(K key, Function mappingFunction) { long now = now(); - V value = get(key); + V value = get(key, now); if (value == null) { CacheSegment segment = getCacheSegment(key); try (ReleasableLock ignored = segment.writeLock.acquire()) { - value = get(key); + value = get(key, now); if (value == null) { value = mappingFunction.apply(key); }