Enable prefix by default on RedisCacheManager

An overhaul of the `RedisCacheManager` is expected in Hopper (to be
consumed by Spring Boot 1.4). One of those changes is to make sure every
key have a decent prefix by default.

This commit enables the use of prefix as it is disabled by default.

Closes gh-5175
This commit is contained in:
Stephane Nicoll
2016-02-25 13:51:59 +01:00
parent af32d6e8ee
commit 416b689359
3 changed files with 9 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ class RedisCacheConfiguration {
@Bean
public RedisCacheManager cacheManager(RedisTemplate<Object, Object> redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
cacheManager.setUsePrefix(true);
List<String> cacheNames = this.cacheProperties.getCacheNames();
if (!cacheNames.isEmpty()) {
cacheManager.setCacheNames(cacheNames);

View File

@@ -200,6 +200,8 @@ public class CacheAutoConfigurationTests {
load(RedisCacheConfiguration.class, "spring.cache.type=redis");
RedisCacheManager cacheManager = validateCacheManager(RedisCacheManager.class);
assertThat(cacheManager.getCacheNames()).isEmpty();
assertThat((Boolean) new DirectFieldAccessor(cacheManager)
.getPropertyValue("usePrefix")).isTrue();
}
@Test