Skip to content

Commit

Permalink
Simplify getCache() implementation in CaffeineCacheManager
Browse files Browse the repository at this point in the history
Closes gh-24376
  • Loading branch information
sbrannen committed Jan 16, 2020
1 parent 61d9787 commit 16e49bf
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,6 +50,7 @@
* @author Ben Manes
* @author Juergen Hoeller
* @author Stephane Nicoll
* @author Sam Brannen
* @since 4.3
* @see CaffeineCache
*/
Expand Down Expand Up @@ -178,17 +179,8 @@ public Collection<String> 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);
}
}
}
return cache;
return this.cacheMap.computeIfAbsent(name, cacheName ->
this.dynamic ? createCaffeineCache(cacheName) : null);
}

/**
Expand Down

0 comments on commit 16e49bf

Please sign in to comment.