业务流程

扩展 Spring Cache 支持多级缓存 - 图2



spring boot starter依赖

  • 方便在 web 环境下使用 cache,已上传至 maven 仓库
  1. <dependency>
  2. <groupId>com.litong.boot</groupId>
  3. <artifactId>multilevel-cache-spring-boot-starter</artifactId>
  4. <version>1.0-SNAPSHOT</version>
  5. </dependency>

使用方法

  • 开启缓存支持

    1. @EnableCaching
    2. public class App {
    3. public static void main(String[] args) {
    4. SpringApplication.run(App.class, args);
    5. }
    6. }
  • 目标接口声明 Spring Cache 注解

  1. @Cacheable(value = "get",key = "#key")
  2. @GetMapping("/get")
  3. public String get(String key){
  4. return "success";
  5. }