|
1 | 1 | /*
|
2 |
| - * Copyright 2011-2015 the original author or authors. |
| 2 | + * Copyright 2011-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -56,7 +56,7 @@ public class RedisCacheManager extends AbstractTransactionSupportingCacheManager
|
56 | 56 |
|
57 | 57 | private final Log logger = LogFactory.getLog(RedisCacheManager.class);
|
58 | 58 |
|
59 |
| - @SuppressWarnings("rawtypes")// |
| 59 | + @SuppressWarnings("rawtypes") // |
60 | 60 | private final RedisOperations redisOperations;
|
61 | 61 |
|
62 | 62 | private boolean usePrefix = false;
|
@@ -93,16 +93,6 @@ public RedisCacheManager(RedisOperations redisOperations, Collection<String> cac
|
93 | 93 | setCacheNames(cacheNames);
|
94 | 94 | }
|
95 | 95 |
|
96 |
| - @Override |
97 |
| - public Cache getCache(String name) { |
98 |
| - Cache cache = super.getCache(name); |
99 |
| - if (cache == null && this.dynamic) { |
100 |
| - return createAndAddCache(name); |
101 |
| - } |
102 |
| - |
103 |
| - return cache; |
104 |
| - } |
105 |
| - |
106 | 96 | /**
|
107 | 97 | * Specify the set of cache names for this CacheManager's 'static' mode. <br>
|
108 | 98 | * The number of caches and their names will be fixed after a call to this method, with no creation of further cache
|
@@ -169,8 +159,21 @@ public void setLoadRemoteCachesOnStartup(boolean loadRemoteCachesOnStartup) {
|
169 | 159 | protected Collection<? extends Cache> loadCaches() {
|
170 | 160 |
|
171 | 161 | Assert.notNull(this.redisOperations, "A redis template is required in order to interact with data store");
|
172 |
| - return addConfiguredCachesIfNecessary(loadRemoteCachesOnStartup ? loadAndInitRemoteCaches() : Collections |
173 |
| - .<Cache> emptyList()); |
| 162 | + |
| 163 | + Set<Cache> caches = new LinkedHashSet<Cache>( |
| 164 | + loadRemoteCachesOnStartup ? loadAndInitRemoteCaches() : new ArrayList<Cache>()); |
| 165 | + |
| 166 | + Set<String> cachesToLoad = new LinkedHashSet<String>(this.configuredCacheNames); |
| 167 | + cachesToLoad.addAll(this.getCacheNames()); |
| 168 | + |
| 169 | + if (!CollectionUtils.isEmpty(cachesToLoad)) { |
| 170 | + |
| 171 | + for (String cacheName : cachesToLoad) { |
| 172 | + caches.add(createCache(cacheName)); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + return caches; |
174 | 177 | }
|
175 | 178 |
|
176 | 179 | /**
|
@@ -206,9 +209,27 @@ protected Collection<? extends Cache> addConfiguredCachesIfNecessary(Collection<
|
206 | 209 | return result;
|
207 | 210 | }
|
208 | 211 |
|
| 212 | + /** |
| 213 | + * Will no longer add the cache to the set of |
| 214 | + * |
| 215 | + * @param cacheName |
| 216 | + * @return |
| 217 | + * @deprecated since 1.8 - please use {@link #getCache(String)}. |
| 218 | + */ |
| 219 | + @Deprecated |
209 | 220 | protected Cache createAndAddCache(String cacheName) {
|
210 |
| - addCache(createCache(cacheName)); |
211 |
| - return super.getCache(cacheName); |
| 221 | + |
| 222 | + Cache cache = super.getCache(cacheName); |
| 223 | + return cache != null ? cache : createCache(cacheName); |
| 224 | + } |
| 225 | + |
| 226 | + /* |
| 227 | + * (non-Javadoc) |
| 228 | + * @see org.springframework.cache.support.AbstractCacheManager#getMissingCache(java.lang.String) |
| 229 | + */ |
| 230 | + @Override |
| 231 | + protected Cache getMissingCache(String name) { |
| 232 | + return this.dynamic ? createCache(name) : null; |
212 | 233 | }
|
213 | 234 |
|
214 | 235 | @SuppressWarnings("unchecked")
|
@@ -282,27 +303,6 @@ protected boolean isUsePrefix() {
|
282 | 303 | return usePrefix;
|
283 | 304 | }
|
284 | 305 |
|
285 |
| - /** |
286 |
| - * The number of caches and their names will be fixed after a call to this method, with no creation of further cache |
287 |
| - * regions at runtime. |
288 |
| - * |
289 |
| - * @see org.springframework.cache.support.AbstractCacheManager#afterPropertiesSet() |
290 |
| - */ |
291 |
| - @Override |
292 |
| - public void afterPropertiesSet() { |
293 |
| - |
294 |
| - if (!CollectionUtils.isEmpty(configuredCacheNames)) { |
295 |
| - |
296 |
| - for (String cacheName : configuredCacheNames) { |
297 |
| - createAndAddCache(cacheName); |
298 |
| - } |
299 |
| - |
300 |
| - configuredCacheNames.clear(); |
301 |
| - } |
302 |
| - |
303 |
| - super.afterPropertiesSet(); |
304 |
| - } |
305 |
| - |
306 | 306 | /* (non-Javadoc)
|
307 | 307 | * @see
|
308 | 308 | org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#decorateCache(org.springframework.cache.Cache)
|
|
0 commit comments