-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
jdk21,springboot3.2.2。
启动类:
@SpringBootApplication
@EnableMethodCache(basePackages = "com.len.jetcache")
public class JetCacheApplication {
public static void main(String[] args) {
SpringApplication.run(JetCacheApplication.class, args);
}
}
controller
@RequestMapping("/add")
public UserInfo add(@RequestParam(value = "userId") String userId) {
return userService.add(userId);
}
service:
@OverRide
@cached(name = "user:cache", cacheType = CacheType.BOTH, key = "#userId")
@cacherefresh(refresh = 60, timeUnit = TimeUnit.MINUTES)
public UserInfo add(String userId) {
log.info("经过了缓存!!!");
return userInfoMapper.selectById(userId);
}
这是jetcache打印的日志信息
2025-11-18T14:07:00.008+08:00 INFO 27789 --- [jetcache] [DefaultExecutor] c.alicp.jetcache.support.StatInfoLogger : jetcache stat from 2025-11-18 14:06:00,005 to 2025-11-18 14:07:00,007
cache | qps| rate| get| hit| fail| expire|avgLoadTime|maxLoadTime
-----------------+----------+-------+--------------+--------------+--------------+--------------+-----------+-----------
user:cache | 0.00| 0.00%| 0| 0| 0| 0| 0.0| 0
user:cache_local | 0.00| 0.00%| 0| 0| 0| 0| 0.0| 0
user:cache_remote| 0.00| 0.00%| 0| 0| 0| 0| 0.0| 0
-----------------+----------+-------+--------------+--------------+--------------+--------------+-----------+-----------
访问add路径的时候,信息可以正常返回,但是数据没有缓存到本地缓存和redis缓存中,配置如下:
#JetCache配置
jetcache:
statIntervalMinutes: 1
areaInCacheName: false
local:
default:
type: caffeine
keyConvertor: fastjson2
remote:
default:
type: redisson
keyConvertor: fastjson2
broadcastChannel: ${spring.application.name}
keyPrefix: ${spring.application.name}
valueEncoder: java
valueDecoder: java
defaultExpireInMillis: 3600000 # 60分钟