@Cacheable缓存解决双冒号::问题
使用spring-data-redis2.x版本时,@Cacheable缓存key值时默认会给vlue或cacheNames后加上双引号
通过配置进行修改即可满足项目需求
@Configuration
public class SpringCacheConfig{
@Bean
public CacheManager cacheManager(LettuceConnectionFactory lettuceConnectionFactory){
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofHour(1)
//变双冒号为单冒号
.computePrefixWith(name - >":")
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()))
.disableCachingNullValues();
RedisCacheManager cacheManager = RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(lettuceConnectionFactory)
.cacheDefaults(config)
.transactionAware()
.build();
return cacheManager;
}
...其他配置
}
本文地址:https://blog.csdn.net/u012725623/article/details/107671343
上一篇: 苏式月饼馅有什么呢?月饼的种类有什么呢?