引入依赖spring-boot-starter-cache

  1. <!--缓存cache-->
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-cache</artifactId>
  5. </dependency>

main使用注解开启缓存功能

  1. //开启缓存功能
  2. @EnableCaching

需要用缓冲的地方,使用 @Cacheable注解,value定义一个变量用来保存结构,key是一个变量不要重复

  1. @Cacheable(value = "cacheSpace", key = "#userid")