@EnableCaching
@Configuration(proxyBeanMethods = false)
public class RedisCacheManagerConfiguration {
// springboot 官方写法
@Bean
public RedisCacheManagerBuilderCustomizer myRedisCacheManagerBuilderCustomizer() {
return (builder) -> builder
.withCacheConfiguration("cache15m", RedisCacheConfiguration
.defaultCacheConfig().entryTtl(Duration.ofMinutes(15)).prefixCacheNameWith("dc_").disableCachingNullValues())
.withCacheConfiguration("cache30m", RedisCacheConfiguration
.defaultCacheConfig().entryTtl(Duration.ofMinutes(30)).prefixCacheNameWith("dc_").disableCachingNullValues())
.withCacheConfiguration("cache1h",RedisCacheConfiguration
.defaultCacheConfig().entryTtl(Duration.ofHours(1)).prefixCacheNameWith("dc_").disableCachingNullValues())
.withCacheConfiguration("cache1d",RedisCacheConfiguration
.defaultCacheConfig().entryTtl(Duration.ofDays(1)).prefixCacheNameWith("dc_").disableCachingNullValues());
}
}
springboot,redis自定义缓存时间配置
最新推荐文章于 2024-07-27 16:02:39 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)