使用Redis缓存

注解介绍

@Cacheable 当方法执行的时候会先访问缓存,如果有直接返回缓存,不执行方法。否则就直接执行方法,并在执行后将返回值放入缓存(condition条件为真,unless条件为假时执行)。

@CacheEvict 当方法执行完清理缓存(一条或多条)

@CachePut 将方法的返回值放入缓存

参数介绍

导入maven坐标

				<!--Redis-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!--spring cache-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>

yml配置文件设置