Commit e1f64eaad2415a54a9c008838b8b6cdca936880f

Authored by YunaiV
1 parent be27ba3a

fix:【框架】支持自定义过期时间的缓存 key,不能忽略租户问题,对应 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1474

yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java
1 package cn.iocoder.yudao.framework.tenant.core.redis; 1 package cn.iocoder.yudao.framework.tenant.core.redis;
2 2
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.StrUtil;
4 import cn.iocoder.yudao.framework.redis.core.TimeoutRedisCacheManager; 5 import cn.iocoder.yudao.framework.redis.core.TimeoutRedisCacheManager;
5 import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; 6 import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
6 import lombok.extern.slf4j.Slf4j; 7 import lombok.extern.slf4j.Slf4j;
@@ -21,6 +22,8 @@ import java.util.Set; @@ -21,6 +22,8 @@ import java.util.Set;
21 @Slf4j 22 @Slf4j
22 public class TenantRedisCacheManager extends TimeoutRedisCacheManager { 23 public class TenantRedisCacheManager extends TimeoutRedisCacheManager {
23 24
  25 + private static final String SPLIT = "#";
  26 +
24 private final Set<String> ignoreCaches; 27 private final Set<String> ignoreCaches;
25 28
26 public TenantRedisCacheManager(RedisCacheWriter cacheWriter, 29 public TenantRedisCacheManager(RedisCacheWriter cacheWriter,
@@ -32,10 +35,11 @@ public class TenantRedisCacheManager extends TimeoutRedisCacheManager { @@ -32,10 +35,11 @@ public class TenantRedisCacheManager extends TimeoutRedisCacheManager {
32 35
33 @Override 36 @Override
34 public Cache getCache(String name) { 37 public Cache getCache(String name) {
  38 + String[] names = StrUtil.splitToArray(name, SPLIT);
35 // 如果开启多租户,则 name 拼接租户后缀 39 // 如果开启多租户,则 name 拼接租户后缀
36 if (!TenantContextHolder.isIgnore() 40 if (!TenantContextHolder.isIgnore()
37 - && TenantContextHolder.getTenantId() != null  
38 - && !CollUtil.contains(ignoreCaches, name)) { 41 + && TenantContextHolder.getTenantId() != null
  42 + && !CollUtil.contains(ignoreCaches, names[0])) {
39 name = name + ":" + TenantContextHolder.getTenantId(); 43 name = name + ":" + TenantContextHolder.getTenantId();
40 } 44 }
41 45
@@ -43,4 +47,4 @@ public class TenantRedisCacheManager extends TimeoutRedisCacheManager { @@ -43,4 +47,4 @@ public class TenantRedisCacheManager extends TimeoutRedisCacheManager {
43 return super.getCache(name); 47 return super.getCache(name);
44 } 48 }
45 49
46 -} 50 -}
  51 +}
47 \ No newline at end of file 52 \ No newline at end of file