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); }
-

浙公网安备 33010602011771号