背景
我们在开发后台项目的时候,经常需要一些借助缓存缓存减少数据库的压力,但又不想引入redis组件,仅仅想使用本地缓存处理经常调用的方法,这里我们使用spring注解@Cacheable 来替代我们常用的Google cache,注解的方式使用起来要更加的便捷。
Maven引入
<!--spring cache start -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId