diff --git a/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java b/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java index 0fd92458746..ba418e2e0c9 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java @@ -18,8 +18,6 @@ package org.springframework.cache.support; import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -33,44 +31,28 @@ import org.springframework.cache.CacheManager; * for disabling caching, typically used for backing cache declarations * without an actual backing store. * - *

Will simply accept any items into the cache not actually storing them. + *

This implementation will simply accept any items into the cache, + * not actually storing them. * * @author Costin Leau * @author Stephane Nicoll + * @author Juergen Hoeller * @since 3.1 * @see NoOpCache */ public class NoOpCacheManager implements CacheManager { - private final ConcurrentMap caches = new ConcurrentHashMap<>(16); + private final ConcurrentMap cacheMap = new ConcurrentHashMap<>(16); - private final Set cacheNames = new LinkedHashSet<>(16); - - /** - * This implementation always returns a {@link Cache} implementation that will not store items. - * Additionally, the request cache will be remembered by the manager for consistency. - */ @Override public @Nullable Cache getCache(String name) { - Cache cache = this.caches.get(name); - if (cache == null) { - this.caches.computeIfAbsent(name, NoOpCache::new); - synchronized (this.cacheNames) { - this.cacheNames.add(name); - } - } - return this.caches.get(name); + return this.cacheMap.computeIfAbsent(name, NoOpCache::new); } - /** - * This implementation returns the name of the caches previously requested. - */ @Override public Collection getCacheNames() { - synchronized (this.cacheNames) { - return Collections.unmodifiableSet(this.cacheNames); - } + return Collections.unmodifiableSet(this.cacheMap.keySet()); } }