@Cacheable
添加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency>
1.注解不生效
@Cacheable(value = "listDetail", key = "#cycleId + '_' + #kepointId")
在需要缓存的类或方法上添加注解@Cacheable,然后在启动类上添加@EnableCaching开启缓存。
2.Cannot find cache named 'XXX' for Builder
@Bean public CacheManager cacheManager(RedisConnectionFactory factory) { RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig() .entryTtl(Duration.ofSeconds(60)) .disableCachingNullValues(); return RedisCacheManager.builder(factory) .cacheDefaults(config) .transactionAware() .build(); }
3,SpringBoot2.0之后将Redis的默认客户端由Jedis更换为lettuce
https://blog.csdn.net/qiuweifan/article/details/122700658