From c4a7da92333ffae26f8a2d666e72fb1564dc25a1 Mon Sep 17 00:00:00 2001 From: wanwan <913752709@qq.com> Date: Thu, 10 Aug 2023 15:26:31 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20=E6=8B=93=E5=B1=95=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=9A=84=20RedisCacheManager=20=E4=BD=BF?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=8D=95=E4=BD=8D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 47698bfc6c1d71d1e628595762e1984d10354c9c. --- .../redis/core/TimeoutRedisCacheManager.java | 38 ++----------------- 1 file changed, 3 insertions(+), 35 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 4de7fe57c..cfdee653d 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 @@ -1,6 +1,5 @@ package cn.iocoder.yudao.framework.redis.core; -import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import org.springframework.boot.convert.DurationStyle; import org.springframework.cache.annotation.Cacheable; @@ -14,8 +13,8 @@ import java.time.temporal.ChronoUnit; /** * 支持自定义过期时间的 {@link RedisCacheManager} 实现类 - *
- * 在 {@link Cacheable#cacheNames()} 格式为 "key#ttl" 时,# 后面的 ttl 为过期时间,单位为最后一个字母(支持的单位有:d天,h小时,m分钟,s秒),默认单位为秒 + * + * 在 {@link Cacheable#cacheNames()} 格式为 "key#ttl" 时,# 后面的 ttl 为过期时间,单位为秒 * * @author 芋道源码 */ @@ -43,41 +42,10 @@ public class TimeoutRedisCacheManager extends RedisCacheManager { // 移除 # 后面的 : 以及后面的内容,避免影响解析 names[1] = StrUtil.subBefore(names[1], StrUtil.COLON, false); // 解析时间 - Duration duration = parseDuration(names[1]); + Duration duration = DurationStyle.detectAndParse(names[1], ChronoUnit.SECONDS); cacheConfig = cacheConfig.entryTtl(duration); } return super.createRedisCache(names[0], cacheConfig); } - /** - * 解析 Duration - * - * @param ttlStr - * @return - */ - private Duration parseDuration(String ttlStr) { - String timeUnit = StrUtil.subSuf(ttlStr, -1); - switch (timeUnit) { - case "d": - return Duration.ofDays(removeSuffix(ttlStr)); - case "h": - return Duration.ofHours(removeSuffix(ttlStr)); - case "m": - return Duration.ofMinutes(removeSuffix(ttlStr)); - case "s": - return Duration.ofSeconds(removeSuffix(ttlStr)); - default: - return Duration.ofSeconds(Long.parseLong(ttlStr)); - } - } - - /** - * 移除多余的后缀 - * - * @param ttlStr - * @return - */ - private Long removeSuffix(String ttlStr) { - return NumberUtil.parseLong(StrUtil.sub(ttlStr, 0, ttlStr.length() - 1)); - } }