fix 修复 OssClient 实例多租户相同key缓存覆盖问题

This commit is contained in:
疯狂的狮子li 2023-05-26 16:29:45 +08:00
parent 13c776ec34
commit 8d69be093e
2 changed files with 10 additions and 3 deletions

View File

@ -45,15 +45,17 @@ public class OssFactory {
throw new OssException("系统异常, '" + configKey + "'配置信息不存在!"); throw new OssException("系统异常, '" + configKey + "'配置信息不存在!");
} }
OssProperties properties = JsonUtils.parseObject(json, OssProperties.class); OssProperties properties = JsonUtils.parseObject(json, OssProperties.class);
OssClient client = CLIENT_CACHE.get(configKey); // 使用租户标识避免多个租户相同key实例覆盖
String key = properties.getTenantId() + ":" + configKey;
OssClient client = CLIENT_CACHE.get(key);
if (client == null) { if (client == null) {
CLIENT_CACHE.put(configKey, new OssClient(configKey, properties)); CLIENT_CACHE.put(key, new OssClient(configKey, properties));
log.info("创建OSS实例 key => {}", configKey); log.info("创建OSS实例 key => {}", configKey);
return CLIENT_CACHE.get(configKey); return CLIENT_CACHE.get(configKey);
} }
// 配置不相同则重新构建 // 配置不相同则重新构建
if (!client.checkPropertiesSame(properties)) { if (!client.checkPropertiesSame(properties)) {
CLIENT_CACHE.put(configKey, new OssClient(configKey, properties)); CLIENT_CACHE.put(key, new OssClient(configKey, properties));
log.info("重载OSS实例 key => {}", configKey); log.info("重载OSS实例 key => {}", configKey);
return CLIENT_CACHE.get(configKey); return CLIENT_CACHE.get(configKey);
} }

View File

@ -10,6 +10,11 @@ import lombok.Data;
@Data @Data
public class OssProperties { public class OssProperties {
/**
* 租户id
*/
private String tenantId;
/** /**
* 访问站点 * 访问站点
*/ */