diff --git a/src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java b/src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java
index ee48d8d26..7f1b903f6 100644
--- a/src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java
+++ b/src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2015 the original author or authors.
+ * Copyright 2011-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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;
@@ -93,16 +93,6 @@ public class RedisCacheManager extends AbstractTransactionSupportingCacheManager
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.
* 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 class RedisCacheManager extends AbstractTransactionSupportingCacheManager
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
- . emptyList());
+
+ Set caches = new LinkedHashSet(
+ loadRemoteCachesOnStartup ? loadAndInitRemoteCaches() : new ArrayList());
+
+ Set cachesToLoad = new LinkedHashSet(this.configuredCacheNames);
+ cachesToLoad.addAll(this.getCacheNames());
+
+ if (!CollectionUtils.isEmpty(cachesToLoad)) {
+
+ for (String cacheName : cachesToLoad) {
+ caches.add(createCache(cacheName));
+ }
+ }
+
+ return caches;
}
/**
@@ -206,9 +209,27 @@ public class RedisCacheManager extends AbstractTransactionSupportingCacheManager
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);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.cache.support.AbstractCacheManager#getMissingCache(java.lang.String)
+ */
+ @Override
+ protected Cache getMissingCache(String name) {
+ return this.dynamic ? createCache(name) : null;
}
@SuppressWarnings("unchecked")
@@ -282,27 +303,6 @@ public class RedisCacheManager extends AbstractTransactionSupportingCacheManager
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)