From d5d5c3cbeb0c4af3656c2261366f5cd85934cf26 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 6 Apr 2024 11:27:00 +0800 Subject: [PATCH] =?UTF-8?q?bugfix=EF=BC=9ASpring=20Cache=20=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4=EF=BC=8C?= =?UTF-8?q?=E5=9C=A8=E5=A4=9A=E7=A7=9F=E6=88=B7=E5=9C=BA=E6=99=AF=E4=B8=8B?= =?UTF-8?q?=EF=BC=8C=E4=BC=9A=E9=A2=9D=E5=A4=96=E6=8B=BC=E6=8E=A5=20#=20?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/redis/core/TimeoutRedisCacheManager.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/core/TimeoutRedisCacheManager.java b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/core/TimeoutRedisCacheManager.java index 3e40c0be6..a835835de 100644 --- a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/core/TimeoutRedisCacheManager.java +++ b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/core/TimeoutRedisCacheManager.java @@ -40,12 +40,15 @@ public class TimeoutRedisCacheManager extends RedisCacheManager { // 核心:通过修改 cacheConfig 的过期时间,实现自定义过期时间 if (cacheConfig != null) { // 移除 # 后面的 : 以及后面的内容,避免影响解析 - names[1] = StrUtil.subBefore(names[1], StrUtil.COLON, false); + String ttlStr = StrUtil.subBefore(names[1], StrUtil.COLON, false); // 获得 ttlStr 时间部分 + names[1] = StrUtil.subAfter(names[1], ttlStr, false); // 移除掉 ttlStr 时间部分 // 解析时间 - Duration duration = parseDuration(names[1]); + Duration duration = parseDuration(ttlStr); cacheConfig = cacheConfig.entryTtl(duration); } - return super.createRedisCache(name, cacheConfig); + + // 创建 RedisCache 对象,需要忽略掉 ttlStr + return super.createRedisCache(names[0] + names[1], cacheConfig); } /**