Skip to content

Commit b47fc35

Browse files
christophstroblmp911de
authored andcommitted
DATAREDIS-539 - Replace call to deprecated addCache in RedisCacheManager.
We now rely on getMissingCache and loadCaches for initialization instead of explicitly calling deprecated addCache method. Original pull request: #212.
1 parent a6ad1a5 commit b47fc35

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2015 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public class RedisCacheManager extends AbstractTransactionSupportingCacheManager
5656

5757
private final Log logger = LogFactory.getLog(RedisCacheManager.class);
5858

59-
@SuppressWarnings("rawtypes")//
59+
@SuppressWarnings("rawtypes") //
6060
private final RedisOperations redisOperations;
6161

6262
private boolean usePrefix = false;
@@ -93,16 +93,6 @@ public RedisCacheManager(RedisOperations redisOperations, Collection<String> cac
9393
setCacheNames(cacheNames);
9494
}
9595

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-
10696
/**
10797
* Specify the set of cache names for this CacheManager's 'static' mode. <br>
10898
* 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) {
169159
protected Collection<? extends Cache> loadCaches() {
170160

171161
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;
174177
}
175178

176179
/**
@@ -206,9 +209,27 @@ protected Collection<? extends Cache> addConfiguredCachesIfNecessary(Collection<
206209
return result;
207210
}
208211

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
209220
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;
212233
}
213234

214235
@SuppressWarnings("unchecked")
@@ -282,27 +303,6 @@ protected boolean isUsePrefix() {
282303
return usePrefix;
283304
}
284305

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-
306306
/* (non-Javadoc)
307307
* @see
308308
org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#decorateCache(org.springframework.cache.Cache)

0 commit comments

Comments
 (0)