jetcache springboot实现

  • jetcache springboot实现

    • 添加依赖

      <dependency>
          <groupId>com.alicp.jetcache</groupId>
          <artifactId>jetcache-starter-redis</artifactId>
      </dependency>
      
    • 配置文件

      jetcache:
        statIntervalMinutes: 15
        areaInCacheName: false
        local:
          default:
            type: linkedhashmap
            keyConvertor: fastjson
            limit: 1000
        remote:
          default:
            type: redis
            keyConvertor: fastjson
            valueEncoder: kryo
            valueDecoder: kryo
            poolConfig:
              minIdle: 5
              maxIdle: 20
              maxTotal: 50
            host: ${spring.redis.host}
            port: ${spring.redis.port}
      
    • 创建配置类

      package com.chaoyang.config.jetcache;
      
      import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
      import com.alicp.jetcache.anno.config.EnableMethodCache;
      import org.springframework.context.annotation.Configuration;
      
      @Configuration
      @EnableCreateCacheAnnotation
      @EnableMethodCache(basePackages = "com.chaoyang.service.impl")
      public class JetcacheConfig {
      }
      
      
    • 实现方法上加注解

      package com.chaoyang.service.impl;
      
      import com.alicp.jetcache.anno.Cached;
      import org.springframework.stereotype.Service;
      
      @Service
      public class TestServiceImpl {
      	
          @Cached(name="testcache", expire = 3600)
          public String test() {
              return "jetcache test " + String.valueOf(System.currentTimeMillis());
          }
      }
      
      
    • 测试接口

      @GetMapping("/test/jetcache")
      public R<String> testJetcache(){
          String test = testServiceImpl.test();
          return R.ok(test);
      }
      
posted @   巫小诗  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示