Skip to content

DATAREDIS-539 - Replace call to deprecated addCache in RedisCacheManager. #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.0.BUILD-SNAPSHOT</version>
<version>1.8.0.DATAREDIS-539-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class RedisCacheManager extends AbstractTransactionSupportingCacheManager

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

@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private final RedisOperations redisOperations;

private boolean usePrefix = false;
Expand Down Expand Up @@ -93,16 +93,6 @@ public RedisCacheManager(RedisOperations redisOperations, Collection<String> cac
setCacheNames(cacheNames);
}

@Override
public Cache getCache(String name) {
Cache cache = super.getCache(name);
if (cache == null && this.dynamic) {
return createAndAddCache(name);
}

return cache;
}

/**
* Specify the set of cache names for this CacheManager's 'static' mode. <br>
* The number of caches and their names will be fixed after a call to this method, with no creation of further cache
Expand Down Expand Up @@ -169,8 +159,21 @@ public void setLoadRemoteCachesOnStartup(boolean loadRemoteCachesOnStartup) {
protected Collection<? extends Cache> loadCaches() {

Assert.notNull(this.redisOperations, "A redis template is required in order to interact with data store");
return addConfiguredCachesIfNecessary(loadRemoteCachesOnStartup ? loadAndInitRemoteCaches() : Collections
.<Cache> emptyList());

Set<Cache> caches = new LinkedHashSet<Cache>(
loadRemoteCachesOnStartup ? loadAndInitRemoteCaches() : new ArrayList<Cache>());

Set<String> cachesToLoad = new LinkedHashSet<String>(this.configuredCacheNames);
cachesToLoad.addAll(this.getCacheNames());

if (!CollectionUtils.isEmpty(cachesToLoad)) {

for (String cacheName : cachesToLoad) {
caches.add(createCache(cacheName));
}
}

return caches;
}

/**
Expand Down Expand Up @@ -206,9 +209,23 @@ protected Collection<? extends Cache> addConfiguredCachesIfNecessary(Collection<
return result;
}

/**
* Will no longer add the cache to the set of
*
* @param cacheName
* @return
* @deprecated since 1.8 - please use {@link #getCache(String)}.
*/
@Deprecated
protected Cache createAndAddCache(String cacheName) {
addCache(createCache(cacheName));
return super.getCache(cacheName);

Cache cache = super.getCache(cacheName);
return cache != null ? cache : createCache(cacheName);
}

@Override
protected Cache getMissingCache(String name) {
return this.dynamic ? createCache(name) : null;
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -282,27 +299,6 @@ protected boolean isUsePrefix() {
return usePrefix;
}

/**
* The number of caches and their names will be fixed after a call to this method, with no creation of further cache
* regions at runtime.
*
* @see org.springframework.cache.support.AbstractCacheManager#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() {

if (!CollectionUtils.isEmpty(configuredCacheNames)) {

for (String cacheName : configuredCacheNames) {
createAndAddCache(cacheName);
}

configuredCacheNames.clear();
}

super.afterPropertiesSet();
}

/* (non-Javadoc)
* @see
org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#decorateCache(org.springframework.cache.Cache)
Expand Down