!562 优化 redisCache

plp
YunaiV 3 years ago
parent 8960a82978
commit 9ff67b479f

@ -7,15 +7,21 @@ import org.springframework.validation.annotation.Validated;
/**
* Cache
*
* @author
* @author Wanwan
*/
@ConfigurationProperties("yudao.cache")
@Data
@Validated
public class YudaoCacheProperties {
/**
* {@link #redisScanBatchSize}
*/
private static final Integer REDIS_SCAN_BATCH_SIZE_DEFAULT = 30;
/**
* redis scan
*/
private Integer redisScanBatchSize = 30;
private Integer redisScanBatchSize = REDIS_SCAN_BATCH_SIZE_DEFAULT;
}

@ -2,7 +2,6 @@ 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;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
@ -10,12 +9,12 @@ import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
/**
* {@link RedisCacheManager}
* <p>
* {@link Cacheable#cacheNames()} "key#ttl" # ttl (dhms)
*
* {@link Cacheable#cacheNames()} "key#ttl" # ttl
* d h m s s
*
* @author
*/
@ -50,34 +49,35 @@ public class TimeoutRedisCacheManager extends RedisCacheManager {
}
/**
* Duration
* Duration
*
* @param ttlStr
* @return
* @param ttlStr
* @return Duration
*/
private Duration parseDuration(String ttlStr) {
String timeUnit = StrUtil.subSuf(ttlStr, -1);
switch (timeUnit) {
case "d":
return Duration.ofDays(removeSuffix(ttlStr));
return Duration.ofDays(removeDurationSuffix(ttlStr));
case "h":
return Duration.ofHours(removeSuffix(ttlStr));
return Duration.ofHours(removeDurationSuffix(ttlStr));
case "m":
return Duration.ofMinutes(removeSuffix(ttlStr));
return Duration.ofMinutes(removeDurationSuffix(ttlStr));
case "s":
return Duration.ofSeconds(removeSuffix(ttlStr));
return Duration.ofSeconds(removeDurationSuffix(ttlStr));
default:
return Duration.ofSeconds(Long.parseLong(ttlStr));
}
}
/**
*
*
*
* @param ttlStr
* @return
* @param ttlStr
* @return
*/
private Long removeSuffix(String ttlStr) {
private Long removeDurationSuffix(String ttlStr) {
return NumberUtil.parseLong(StrUtil.sub(ttlStr, 0, ttlStr.length() - 1));
}
}

@ -204,8 +204,6 @@ yudao:
order:
app-id: 1 # 商户编号
expire-time: 2h # 支付的过期时间
cache: # spring cache 相关配置
redis-scan-batch-size: 30 # redis scan 一次返回数量
debug: false

Loading…
Cancel
Save