Skip to content

Commit 7f6b01c

Browse files
committed
Make sure Redis cache prefix includes cache name
This commit maps 'spring.cache.redis.key-prefix' to the new 'prefixCacheNameWith' method introduced in Spring Data Neumann. This makes sure that the configured prefix includes the cache name. Closes gh-16676
1 parent 3fe4245 commit 7f6b01c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -85,7 +85,7 @@ private org.springframework.data.redis.cache.RedisCacheConfiguration createConfi
8585
config = config.entryTtl(redisProperties.getTimeToLive());
8686
}
8787
if (redisProperties.getKeyPrefix() != null) {
88-
config = config.prefixKeysWith(redisProperties.getKeyPrefix());
88+
config = config.prefixCacheNameWith(redisProperties.getKeyPrefix());
8989
}
9090
if (!redisProperties.isCacheNullValues()) {
9191
config = config.disableCachingNullValues();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -252,7 +252,7 @@ void redisCacheExplicit() {
252252
RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(cacheManager);
253253
assertThat(redisCacheConfiguration.getTtl()).isEqualTo(java.time.Duration.ofSeconds(15));
254254
assertThat(redisCacheConfiguration.getAllowCacheNullValues()).isFalse();
255-
assertThat(redisCacheConfiguration.getKeyPrefixFor("keyName")).isEqualTo("prefix");
255+
assertThat(redisCacheConfiguration.getKeyPrefixFor("MyCache")).isEqualTo("prefixMyCache::");
256256
assertThat(redisCacheConfiguration.usePrefix()).isTrue();
257257
});
258258
}

0 commit comments

Comments
 (0)