Browse Source

Polish "Document RedisCacheManagerBuilderCustomizer"

See gh-19819
pull/19959/head
Stephane Nicoll 6 years ago
parent
commit
3dba4c8f4e
  1. 17
      spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
  2. 10
      spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/RedisCacheManagerCustomizationExample.java

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

@ -4771,19 +4771,20 @@ For instance, the following configuration creates `cache1` and `cache2` caches w @@ -4771,19 +4771,20 @@ For instance, the following configuration creates `cache1` and `cache2` caches w
spring.cache.redis.time-to-live=600000
----
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`
programmatically by declaring `RedisCacheManagerBuilderCustomizer` bean(s) as shown in the following example:
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.
We strongly recommend keeping this setting enabled if you create your own `RedisCacheManager`.
TIP: You can take full control of the default configuration by adding a `RedisCacheConfiguration` `@Bean` of your own.
This can be useful if you're looking for customizing the default serialization strategy.
If you need more control over the configuration, consider registering a `RedisCacheManagerBuilderCustomizer` bean.
The following example shows a customizer that configures a specific time to live for `cache1` and `cache2`:
[source,java,indent=0]
----
include::{code-examples}/cache/redis/RedisCacheManagerBuilderCustomizerConfiguration.java[tag=configuration]
include::{code-examples}/cache/RedisCacheManagerCustomizationExample.java[tag=configuration]
----
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.
We strongly recommend keeping this setting enabled if you create your own `RedisCacheManager`.
TIP: You can take full control of the configuration by adding a `RedisCacheConfiguration` `@Bean` of your own.
This can be useful if you're looking for customizing the serialization strategy.

10
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/redis/RedisCacheManagerBuilderCustomizerConfiguration.java → spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/cache/RedisCacheManagerCustomizationExample.java vendored

@ -14,6 +14,8 @@ @@ -14,6 +14,8 @@
* limitations under the License.
*/
package org.springframework.boot.docs.cache;
import java.time.Duration;
import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer;
@ -27,12 +29,12 @@ import org.springframework.data.redis.cache.RedisCacheConfiguration; @@ -27,12 +29,12 @@ import org.springframework.data.redis.cache.RedisCacheConfiguration;
*
* @author Dmytro Nosan
*/
// tag::configuration[]
@Configuration(proxyBeanMethods = false)
public class RedisCacheManagerBuilderCustomizerConfiguration {
public class RedisCacheManagerCustomizationExample {
// tag::configuration[]
@Bean
public RedisCacheManagerBuilderCustomizer ttlRedisCacheManagerBuilderCustomizer() {
public RedisCacheManagerBuilderCustomizer myRedisCacheManagerBuilderCustomizer() {
return (builder) -> builder
.withCacheConfiguration("cache1",
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(10)))
@ -40,6 +42,6 @@ public class RedisCacheManagerBuilderCustomizerConfiguration { @@ -40,6 +42,6 @@ public class RedisCacheManagerBuilderCustomizerConfiguration {
RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(1)));
}
// end::configuration[]
}
// end::configuration[]
Loading…
Cancel
Save