|
@@ -1,5 +1,6 @@
|
|
|
package cn.iocoder.yudao.framework.tenant.core.redis;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.iocoder.yudao.framework.redis.core.TimeoutRedisCacheManager;
|
|
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -8,6 +9,8 @@ import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
|
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
|
|
import org.springframework.data.redis.cache.RedisCacheWriter;
|
|
|
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
/**
|
|
|
* 多租户的 {@link RedisCacheManager} 实现类
|
|
|
*
|
|
@@ -18,16 +21,21 @@ import org.springframework.data.redis.cache.RedisCacheWriter;
|
|
|
@Slf4j
|
|
|
public class TenantRedisCacheManager extends TimeoutRedisCacheManager {
|
|
|
|
|
|
+ private final Set<String> ignoreCaches;
|
|
|
+
|
|
|
public TenantRedisCacheManager(RedisCacheWriter cacheWriter,
|
|
|
- RedisCacheConfiguration defaultCacheConfiguration) {
|
|
|
+ RedisCacheConfiguration defaultCacheConfiguration,
|
|
|
+ Set<String> ignoreCaches) {
|
|
|
super(cacheWriter, defaultCacheConfiguration);
|
|
|
+ this.ignoreCaches = ignoreCaches;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Cache getCache(String name) {
|
|
|
// 如果开启多租户,则 name 拼接租户后缀
|
|
|
if (!TenantContextHolder.isIgnore()
|
|
|
- && TenantContextHolder.getTenantId() != null) {
|
|
|
+ && TenantContextHolder.getTenantId() != null
|
|
|
+ && !CollUtil.contains(ignoreCaches, name)) {
|
|
|
name = name + ":" + TenantContextHolder.getTenantId();
|
|
|
}
|
|
|
|