Revert "feat: 拓展 支持自定义过期时间的 RedisCacheManager 使支持自定义过期时间单位"

This reverts commit 47698bfc6c.
plp
wanwan 3 years ago
parent e1fe21f24c
commit c4a7da9233

@ -1,6 +1,5 @@
package cn.iocoder.yudao.framework.redis.core; package cn.iocoder.yudao.framework.redis.core;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import org.springframework.boot.convert.DurationStyle; import org.springframework.boot.convert.DurationStyle;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
@ -14,8 +13,8 @@ import java.time.temporal.ChronoUnit;
/** /**
* {@link RedisCacheManager} * {@link RedisCacheManager}
* <p> *
* {@link Cacheable#cacheNames()} "key#ttl" # ttl (dhms) * {@link Cacheable#cacheNames()} "key#ttl" # ttl
* *
* @author * @author
*/ */
@ -43,41 +42,10 @@ public class TimeoutRedisCacheManager extends RedisCacheManager {
// 移除 # 后面的 : 以及后面的内容,避免影响解析 // 移除 # 后面的 : 以及后面的内容,避免影响解析
names[1] = StrUtil.subBefore(names[1], StrUtil.COLON, false); 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); cacheConfig = cacheConfig.entryTtl(duration);
} }
return super.createRedisCache(names[0], cacheConfig); 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));
}
} }

Loading…
Cancel
Save