Avoid unnecessary synchronization for non-existent missing caches

Closes gh-23635
This commit is contained in:
Juergen Hoeller 2019-09-25 12:10:23 +02:00
parent da44a247cb
commit 6a08bfdff7
1 changed files with 10 additions and 9 deletions

View File

@ -87,25 +87,26 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
@Override @Override
@Nullable @Nullable
public Cache getCache(String name) { public Cache getCache(String name) {
// Quick check for existing cache...
Cache cache = this.cacheMap.get(name); Cache cache = this.cacheMap.get(name);
if (cache != null) { if (cache != null) {
return cache; return cache;
} }
else {
// Fully synchronize now for missing cache creation... // The provider may support on-demand cache creation...
Cache missingCache = getMissingCache(name);
if (missingCache != null) {
// Fully synchronize now for missing cache registration
synchronized (this.cacheMap) { synchronized (this.cacheMap) {
cache = this.cacheMap.get(name); cache = this.cacheMap.get(name);
if (cache == null) { if (cache == null) {
cache = getMissingCache(name); cache = decorateCache(missingCache);
if (cache != null) { this.cacheMap.put(name, cache);
cache = decorateCache(cache); updateCacheNames(name);
this.cacheMap.put(name, cache);
updateCacheNames(name);
}
} }
return cache;
} }
} }
return cache;
} }
@Override @Override