diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CacheConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CacheConstants.java index 808dfe2a1..d3623f892 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CacheConstants.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CacheConstants.java @@ -8,6 +8,13 @@ package com.pig4cloud.pigx.common.core.constant; */ public interface CacheConstants { + /** + * 全局缓存,在缓存名称上加上该前缀表示该缓存不区分租户,比如: + *

+ * {@code @Cacheable(value = CacheConstants.GLOBALLY+CacheConstants.MENU_DETAILS, key = "#roleId + '_menu'", unless = "#result == null")} + */ + String GLOBALLY = "gl@"; + /** * 菜单信息缓存 */ diff --git a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/cache/RedisAutoCacheManager.java b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/cache/RedisAutoCacheManager.java index 24595b95e..28563f73c 100644 --- a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/cache/RedisAutoCacheManager.java +++ b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/cache/RedisAutoCacheManager.java @@ -18,6 +18,7 @@ package com.pig4cloud.pigx.common.data.cache; import cn.hutool.core.util.StrUtil; +import com.pig4cloud.pigx.common.core.constant.CacheConstants; import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.cache.Cache; @@ -73,6 +74,10 @@ public class RedisAutoCacheManager extends RedisCacheManager { */ @Override public Cache getCache(String name) { + // see https://gitee.wang/pig/pigx/issues/613 + if(name.startsWith(CacheConstants.GLOBALLY)){ + return super.getCache(name); + } return super.getCache(TenantContextHolder.getTenantId() + StrUtil.COLON + name); } }