Spring 3.1 开始 官方文档:https://docs.spring.io/spring-framework/docs/5.1.18.RELEASE/spring-framework-reference/integration.html#cache
Cache & CacheManager
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-cache --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.自动配置
CacheAutoConfiguration会导入 RedisCacheConfiguration
自动配好了缓存管理器RedismanagerCache
3.手动配置
spring.cache.type=redis
4.测试使用
@Cacheable : 触发将数据保存到缓存的操作
@CacheEvict : 触发将数据从缓存中删除的操作
@CachePut : 不影响方法执行,更新缓存
@Caching : 组合以上多个操作
@CacheConfig :在类级别共享缓存的相同配置
【缓存的分区(按照业务类型分)】 @Cacheable("category")
3.默认行为:
4.自定义行为
原文:https://www.cnblogs.com/sgrslimJ/p/13723571.html