Skip to content

Commit

Permalink
Avoid unnecessary synchronization for non-existent missing caches
Browse files Browse the repository at this point in the history
Closes gh-23635
  • Loading branch information
jhoeller committed Sep 25, 2019
1 parent da44a24 commit 6a08bfd
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,26 @@ public void initializeCaches() {
@Override
@Nullable
public Cache getCache(String name) {
// Quick check for existing cache...
Cache cache = this.cacheMap.get(name);
if (cache != null) {
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) {
cache = this.cacheMap.get(name);
if (cache == null) {
cache = getMissingCache(name);
if (cache != null) {
cache = decorateCache(cache);
this.cacheMap.put(name, cache);
updateCacheNames(name);
}
cache = decorateCache(missingCache);
this.cacheMap.put(name, cache);
updateCacheNames(name);
}
return cache;
}
}
return cache;
}

@Override
Expand Down

0 comments on commit 6a08bfd

Please sign in to comment.