Spring Boot 项目@Cacheable缓存注解+Redis使用

对于重复使用的查询数据,可以从缓存中获取,而不用走接口;

1先在springboot主启动类上加@EnableCaching缓存注解

Spring Boot 项目@Cacheable缓存注解+Redis使用_第1张图片

 2 在需要使用缓存的方法上加上缓存注解,指定cacheNames/value  Spring Boot 项目@Cacheable缓存注解+Redis使用_第2张图片

 

yml  redis的配置

Spring Boot 项目@Cacheable缓存注解+Redis使用_第3张图片

可以通过Redis图形化工具查看当前的key,下次接口请求的时候就直接是从缓存中读取 

Spring Boot 项目@Cacheable缓存注解+Redis使用_第4张图片

下图是介绍缓存的过期时间的配置 

Spring Boot 项目@Cacheable缓存注解+Redis使用_第5张图片

你可能感兴趣的:(缓存,redis,spring,boot)