如果没有引入其他缓存依赖时,springboot默认使用ConcurrenMapCacheManager作为缓存管理器
本文介绍使用redis缓存
支持的缓存类型
- Generic
- JCache (JSR-107) (EhCache 3, Hazelcast, Infinispan, and others)
- EhCache 2.x
- Hazelcast
- Infinispan
- Couchbase
- Redis
- Caffeine
- Simple
也可以自己实现CacheManager
- 引入依赖
<!-- 缓存依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- redis依赖,不引入则默认使用ConcurrenMapCacheManager -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
- 修改配置文件
spring:
redis:
#地址
host: localhost
#端口