Skip to content

Commit 50074f0

Browse files
committed
Merge branch '6.0.x'
2 parents 31a51cc + 60865ea commit 50074f0

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,11 @@ public Collection<String> getCacheNames() {
189189
@Override
190190
@Nullable
191191
public Cache getCache(String name) {
192-
if (this.dynamic) {
193-
Cache cache = this.cacheMap.get(name);
194-
return (cache != null) ? cache : this.cacheMap.computeIfAbsent(name, this::createCaffeineCache);
195-
}
196-
else {
197-
return this.cacheMap.get(name);
192+
Cache cache = this.cacheMap.get(name);
193+
if (cache == null && this.dynamic) {
194+
cache = this.cacheMap.computeIfAbsent(name, this::createCaffeineCache);
198195
}
196+
return cache;
199197
}
200198

201199

spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -165,13 +165,7 @@ public Collection<String> getCacheNames() {
165165
public Cache getCache(String name) {
166166
Cache cache = this.cacheMap.get(name);
167167
if (cache == null && this.dynamic) {
168-
synchronized (this.cacheMap) {
169-
cache = this.cacheMap.get(name);
170-
if (cache == null) {
171-
cache = createConcurrentMapCache(name);
172-
this.cacheMap.put(name, cache);
173-
}
174-
}
168+
cache = this.cacheMap.computeIfAbsent(name, this::createConcurrentMapCache);
175169
}
176170
return cache;
177171
}

0 commit comments

Comments
 (0)