Simplify getCache() implementation in CaffeineCacheManager

Closes gh-24376
This commit is contained in:
Sam Brannen 2020-01-16 15:07:14 +01:00
parent 61d9787b98
commit 16e49bf0c9
1 changed files with 4 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -50,6 +50,7 @@ import org.springframework.util.ObjectUtils;
* @author Ben Manes * @author Ben Manes
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Sam Brannen
* @since 4.3 * @since 4.3
* @see CaffeineCache * @see CaffeineCache
*/ */
@ -178,17 +179,8 @@ public class CaffeineCacheManager implements CacheManager {
@Override @Override
@Nullable @Nullable
public Cache getCache(String name) { public Cache getCache(String name) {
Cache cache = this.cacheMap.get(name); return this.cacheMap.computeIfAbsent(name, cacheName ->
if (cache == null && this.dynamic) { this.dynamic ? createCaffeineCache(cacheName) : null);
synchronized (this.cacheMap) {
cache = this.cacheMap.get(name);
if (cache == null) {
cache = createCaffeineCache(name);
this.cacheMap.put(name, cache);
}
}
}
return cache;
} }
/** /**