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); }
-
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端