🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 1.在redisConfig中开启缓存注解 **@EnableCaching** ~~~ @Configuration @Slf4j @EnableCaching public class RedisConfig { ~~~ ### 2.配置缓存管理器 ~~~ //缓存管理器 @Bean public CacheManager cacheManager(RedisTemplate redisTemplate) { //缓存配置对象 RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig() .entryTtl(Duration.ofMinutes(30L)) //设置缓存的默认超时时间:30分钟 .disableCachingNullValues() //如果是空值,不缓存 .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisTemplate.getKeySerializer())) //设置key序列化器 .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisTemplate.getValueSerializer()));//设置value序列 return RedisCacheManager .builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory)) .cacheDefaults(configuration).build(); } ~~~