ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
![](https://img.kancloud.cn/c4/63/c463ce8a29434da74d4f3769f9430020_1336x454.png) Spring 默认使用的缓存管理器是 ConcurrentMapCacheManager,当引入 spring-boot-starter-data-redis 后则缓存管理器变为 RedisCacheManager,则缓存的数据不是放在内存中了,而是放在 Redis 中。 ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> ``` <br/> ```java @Service public class StudentService { @Autowired private RedisCacheManager redisCacheManager; public void useManager(Student student) { //获取缓存组件 //如果缓存组件student不存在会自动创建 Cache cache = redisCacheManager.getCache("student"); //更新缓存 put(key, data) cache.put(student.getId(), student); //获取缓存 get(key, Class) Student student1 = cache.get(student.getId(), Student.class); //Cache还提供了其它的API,可根据情况调用 } } ```