Commit 416b6893 authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent af32d6e8
......@@ -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);
......
......@@ -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
......
......@@ -3374,6 +3374,12 @@ If Redis is available and configured, the `RedisCacheManager` is auto-configured
also possible to create additional caches on startup using the `spring.cache.cache-names`
property.
[NOTE]
====
By default, a key prefix is added to prevent that if two separate caches use the same
key, Redis would have overlapping keys and be likely to return invalid values. We strongly
recommend to keep this setting enabled if you create your own `RedisCacheManager`.
====
[[boot-features-caching-provider-guava]]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment