|
18 | 18 |
|
19 | 19 | import java.util.Collection; |
20 | 20 | import java.util.Collections; |
21 | | -import java.util.LinkedHashSet; |
22 | | -import java.util.Set; |
23 | 21 | import java.util.concurrent.ConcurrentHashMap; |
24 | 22 | import java.util.concurrent.ConcurrentMap; |
25 | 23 |
|
|
33 | 31 | * for disabling caching, typically used for backing cache declarations |
34 | 32 | * without an actual backing store. |
35 | 33 | * |
36 | | - * <p>Will simply accept any items into the cache not actually storing them. |
| 34 | + * <p>This implementation will simply accept any items into the cache, |
| 35 | + * not actually storing them. |
37 | 36 | * |
38 | 37 | * @author Costin Leau |
39 | 38 | * @author Stephane Nicoll |
| 39 | + * @author Juergen Hoeller |
40 | 40 | * @since 3.1 |
41 | 41 | * @see NoOpCache |
42 | 42 | */ |
43 | 43 | public class NoOpCacheManager implements CacheManager { |
44 | 44 |
|
45 | | - private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<>(16); |
| 45 | + private final ConcurrentMap<String, Cache> cacheMap = new ConcurrentHashMap<>(16); |
46 | 46 |
|
47 | | - private final Set<String> cacheNames = new LinkedHashSet<>(16); |
48 | 47 |
|
49 | | - |
50 | | - /** |
51 | | - * This implementation always returns a {@link Cache} implementation that will not store items. |
52 | | - * Additionally, the request cache will be remembered by the manager for consistency. |
53 | | - */ |
54 | 48 | @Override |
55 | 49 | public @Nullable Cache getCache(String name) { |
56 | | - Cache cache = this.caches.get(name); |
57 | | - if (cache == null) { |
58 | | - this.caches.computeIfAbsent(name, NoOpCache::new); |
59 | | - synchronized (this.cacheNames) { |
60 | | - this.cacheNames.add(name); |
61 | | - } |
62 | | - } |
63 | | - return this.caches.get(name); |
| 50 | + return this.cacheMap.computeIfAbsent(name, NoOpCache::new); |
64 | 51 | } |
65 | 52 |
|
66 | | - /** |
67 | | - * This implementation returns the name of the caches previously requested. |
68 | | - */ |
69 | 53 | @Override |
70 | 54 | public Collection<String> getCacheNames() { |
71 | | - synchronized (this.cacheNames) { |
72 | | - return Collections.unmodifiableSet(this.cacheNames); |
73 | | - } |
| 55 | + return Collections.unmodifiableSet(this.cacheMap.keySet()); |
74 | 56 | } |
75 | 57 |
|
76 | 58 | } |
0 commit comments