Commit d5d5c3cbeb0c4af3656c2261366f5cd85934cf26
1 parent
05af77b7
bugfix:Spring Cache 自定义过期时间,在多租户场景下,会额外拼接 # 的问题
Showing
1 changed file
with
6 additions
and
3 deletions
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 { | @@ -40,12 +40,15 @@ public class TimeoutRedisCacheManager extends RedisCacheManager { | ||
| 40 | // 核心:通过修改 cacheConfig 的过期时间,实现自定义过期时间 | 40 | // 核心:通过修改 cacheConfig 的过期时间,实现自定义过期时间 |
| 41 | if (cacheConfig != null) { | 41 | if (cacheConfig != null) { |
| 42 | // 移除 # 后面的 : 以及后面的内容,避免影响解析 | 42 | // 移除 # 后面的 : 以及后面的内容,避免影响解析 |
| 43 | - names[1] = StrUtil.subBefore(names[1], StrUtil.COLON, false); | 43 | + String ttlStr = StrUtil.subBefore(names[1], StrUtil.COLON, false); // 获得 ttlStr 时间部分 |
| 44 | + names[1] = StrUtil.subAfter(names[1], ttlStr, false); // 移除掉 ttlStr 时间部分 | ||
| 44 | // 解析时间 | 45 | // 解析时间 |
| 45 | - Duration duration = parseDuration(names[1]); | 46 | + Duration duration = parseDuration(ttlStr); |
| 46 | cacheConfig = cacheConfig.entryTtl(duration); | 47 | cacheConfig = cacheConfig.entryTtl(duration); |
| 47 | } | 48 | } |
| 48 | - return super.createRedisCache(name, cacheConfig); | 49 | + |
| 50 | + // 创建 RedisCache 对象,需要忽略掉 ttlStr | ||
| 51 | + return super.createRedisCache(names[0] + names[1], cacheConfig); | ||
| 49 | } | 52 | } |
| 50 | 53 | ||
| 51 | /** | 54 | /** |