【发布时间】:2019-11-06 01:36:17
【问题描述】:
我有一个带有 Redis 缓存的 Spring Boot 2 应用程序。在我覆盖 CacheManager bean 之前,它工作得很好。
问题:以下配置属性被忽略(我无法再关闭缓存):
spring.cache.type=none
虽然according to the documentation 应该可以工作。
问题:如何使spring.cache.type=none 工作?
有一个解决方法like this,但这远不是一个好的解决方案。
更多细节:我的配置如下所示:
@Configuration
public class CacheConfiguration {
@Bean
RedisCacheWriter redisCacheWriter(RedisConnectionFactory connectionFactory) {
return RedisCacheWriter.lockingRedisCacheWriter(connectionFactory);
}
@Bean
CacheManager cacheManager(RedisCacheWriter redisCacheWriter) {
Map<String, RedisCacheConfiguration> ttlConfiguration = ...
RedisCacheConfiguration defaultTtlConfiguration = ...
return new RedisCacheManager(
redisCacheWriter, defaultTtlConfiguration, ttlConfiguration
);
}
}
【问题讨论】:
-
通过手动配置
CacheManager,您将禁用自动配置,从而禁用spring.cache注释的处理。如果你想使用这个属性,你必须自己阅读和处理它。
标签: java spring spring-boot redis spring-cache