Skip to content

Commit 3dba4c8

Browse files
committed
Polish "Document RedisCacheManagerBuilderCustomizer"
See gh-19819
1 parent 61d8bac commit 3dba4c8

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4771,19 +4771,20 @@ For instance, the following configuration creates `cache1` and `cache2` caches w
47714771
spring.cache.redis.time-to-live=600000
47724772
----
47734773

4774-
If you require more control over `RedisCacheManager` e.g. set _time to live_ for the particular caches, you can customize `org.springframework.data.redis.cache.RedisCacheManager$RedisCacheManagerBuilder`
4775-
programmatically by declaring `RedisCacheManagerBuilderCustomizer` bean(s) as shown in the following example:
4774+
NOTE: By default, a key prefix is added so that, if two separate caches use the same key, Redis does not have overlapping keys and cannot return invalid values.
4775+
We strongly recommend keeping this setting enabled if you create your own `RedisCacheManager`.
4776+
4777+
TIP: You can take full control of the default configuration by adding a `RedisCacheConfiguration` `@Bean` of your own.
4778+
This can be useful if you're looking for customizing the default serialization strategy.
4779+
4780+
If you need more control over the configuration, consider registering a `RedisCacheManagerBuilderCustomizer` bean.
4781+
The following example shows a customizer that configures a specific time to live for `cache1` and `cache2`:
47764782

47774783
[source,java,indent=0]
47784784
----
4779-
include::{code-examples}/cache/redis/RedisCacheManagerBuilderCustomizerConfiguration.java[tag=configuration]
4785+
include::{code-examples}/cache/RedisCacheManagerCustomizationExample.java[tag=configuration]
47804786
----
47814787

4782-
NOTE: By default, a key prefix is added so that, if two separate caches use the same key, Redis does not have overlapping keys and cannot return invalid values.
4783-
We strongly recommend keeping this setting enabled if you create your own `RedisCacheManager`.
4784-
4785-
TIP: You can take full control of the configuration by adding a `RedisCacheConfiguration` `@Bean` of your own.
4786-
This can be useful if you're looking for customizing the serialization strategy.
47874788

47884789

47894790

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
package org.springframework.boot.docs.cache;
18+
1719
import java.time.Duration;
1820

1921
import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer;
@@ -27,19 +29,19 @@
2729
*
2830
* @author Dmytro Nosan
2931
*/
30-
// tag::configuration[]
3132
@Configuration(proxyBeanMethods = false)
32-
public class RedisCacheManagerBuilderCustomizerConfiguration {
33+
public class RedisCacheManagerCustomizationExample {
3334

35+
// tag::configuration[]
3436
@Bean
35-
public RedisCacheManagerBuilderCustomizer ttlRedisCacheManagerBuilderCustomizer() {
37+
public RedisCacheManagerBuilderCustomizer myRedisCacheManagerBuilderCustomizer() {
3638
return (builder) -> builder
3739
.withCacheConfiguration("cache1",
3840
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(10)))
3941
.withCacheConfiguration("cache2",
4042
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(1)));
4143

4244
}
45+
// end::configuration[]
4346

4447
}
45-
// end::configuration[]

0 commit comments

Comments
 (0)