From c136b8b27b07eb26266326d50ec1fe1548cc6481 Mon Sep 17 00:00:00 2001 From: Kwangyong Kim Date: Thu, 16 Jan 2020 17:16:05 +0900 Subject: [PATCH] Simplify getCache() method in CaffeineCacheManager Signed-off-by: Kwangyong Kim --- .../cache/caffeine/CaffeineCacheManager.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java index 54331f8909d0..6d0e76ca0063 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java @@ -178,17 +178,11 @@ public Collection getCacheNames() { @Override @Nullable public Cache getCache(String name) { - Cache cache = this.cacheMap.get(name); - if (cache == null && this.dynamic) { - synchronized (this.cacheMap) { - cache = this.cacheMap.get(name); - if (cache == null) { - cache = createCaffeineCache(name); - this.cacheMap.put(name, cache); - } - } + if (this.dynamic) { + return this.cacheMap.computeIfAbsent(name, this::createCaffeineCache); } - return cache; + + return this.cacheMap.get(name); } /**