@Configuration
public class RedisCacheConfig {
//设置失效时间
private static final Map<String, Duration> cacheMap;
static {
//配置哪些缓存需要设置过期时间 以及过期时间是多少
cacheMap = ImmutableMap.<String, Duration>builder().put("videos", Duration.ofSeconds(30L)).build();
// cacheMap.put("") //添加新的缓存失效时间
}
//配置RedisCacheManagerBuilderCustomizer对象
@Bean
public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() {
return (builder) -> {
//根据不同的cachename设置不同的失效时间
for (Map.Entry<String, Duration> entry : cacheMap.entrySet()) {
builder.withCacheConfiguration(entry.getKey(),
RedisCacheConfiguration.defaultCacheConfig().entryTtl(entry.getValue()));
}
};
}
}
最后修改:2022 年 04 月 23 日 10 : 22 AM
© 允许规范转载
END
本文作者: 依桐
文章标题:SpringCache缓存指定失效时间配置类
本文地址:https://www.jufb.cn/archives/116.html
版权说明:若无注明,本文皆依桐博客原创,转载请保留文章出处。
文章标题:SpringCache缓存指定失效时间配置类
本文地址:https://www.jufb.cn/archives/116.html
版权说明:若无注明,本文皆依桐博客原创,转载请保留文章出处。