diff --git a/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent.QQ/LINGYUN/Abp/Tencent/QQ/AbpTencentQQCacheItem.cs b/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent.QQ/LINGYUN/Abp/Tencent/QQ/AbpTencentQQCacheItem.cs index 09e993fdb..4079124a5 100644 --- a/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent.QQ/LINGYUN/Abp/Tencent/QQ/AbpTencentQQCacheItem.cs +++ b/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent.QQ/LINGYUN/Abp/Tencent/QQ/AbpTencentQQCacheItem.cs @@ -4,7 +4,7 @@ namespace LINGYUN.Abp.Tencent.QQ; public class AbpTencentQQCacheItem { - public const string CacheKeyFormat = "pn:{0},pk:{1}"; + public const string CacheKeyFormat = "pn:tenant-cloud,n:qq"; public string AppId { get; set; } public string AppKey { get; set; } public bool IsMobile { get; set; } @@ -23,8 +23,8 @@ public class AbpTencentQQCacheItem IsMobile = isMobile; } - public static string CalculateCacheKey(Guid? tenantId = null) + public static string CalculateCacheKey() { - return string.Format(CacheKeyFormat, tenantId.HasValue ? tenantId.Value.ToString() : "global", "tenant-qq"); + return CacheKeyFormat; } } diff --git a/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent.QQ/LINGYUN/Abp/Tencent/QQ/AbpTencentQQOptionsManager.cs b/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent.QQ/LINGYUN/Abp/Tencent/QQ/AbpTencentQQOptionsManager.cs index 46f81485c..86242a8e1 100644 --- a/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent.QQ/LINGYUN/Abp/Tencent/QQ/AbpTencentQQOptionsManager.cs +++ b/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent.QQ/LINGYUN/Abp/Tencent/QQ/AbpTencentQQOptionsManager.cs @@ -3,7 +3,6 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using System; using System.Threading.Tasks; -using Volo.Abp.MultiTenancy; using Volo.Abp.Options; using Volo.Abp.Settings; @@ -12,17 +11,14 @@ namespace LINGYUN.Abp.Tencent.QQ; public class AbpTencentQQOptionsManager : AbpDynamicOptionsManager { protected IMemoryCache TencentCache { get; } - protected ICurrentTenant CurrentTenant { get; } protected ISettingProvider SettingProvider { get; } public AbpTencentQQOptionsManager( IMemoryCache tencentCache, - ICurrentTenant currentTenant, ISettingProvider settingProvider, IOptionsFactory factory) : base(factory) { TencentCache = tencentCache; - CurrentTenant = currentTenant; SettingProvider = settingProvider; } @@ -37,7 +33,7 @@ public class AbpTencentQQOptionsManager : AbpDynamicOptionsManager GetCacheItemAsync() { - var cacheKey = AbpTencentQQCacheItem.CalculateCacheKey(CurrentTenant.Id); + var cacheKey = AbpTencentQQCacheItem.CalculateCacheKey(); var cacheItem = await TencentCache.GetOrCreateAsync( cacheKey, diff --git a/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent/LINGYUN/Abp/Tencent/AbstractTencentCloudClientFactory.cs b/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent/LINGYUN/Abp/Tencent/AbstractTencentCloudClientFactory.cs index 912501af7..7d625425a 100644 --- a/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent/LINGYUN/Abp/Tencent/AbstractTencentCloudClientFactory.cs +++ b/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent/LINGYUN/Abp/Tencent/AbstractTencentCloudClientFactory.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.Caching.Memory; using System.Threading.Tasks; using Volo.Abp; -using Volo.Abp.MultiTenancy; using Volo.Abp.Settings; namespace LINGYUN.Abp.Tencent; @@ -10,16 +9,13 @@ namespace LINGYUN.Abp.Tencent; public abstract class AbstractTencentCloudClientFactory { protected IMemoryCache ClientCache { get; } - protected ICurrentTenant CurrentTenant { get; } protected ISettingProvider SettingProvider { get; } public AbstractTencentCloudClientFactory( IMemoryCache clientCache, - ICurrentTenant currentTenant, ISettingProvider settingProvider) { ClientCache = clientCache; - CurrentTenant = currentTenant; SettingProvider = settingProvider; } @@ -35,12 +31,13 @@ public abstract class AbstractTencentCloudClientFactory protected async virtual Task GetClientCacheItemAsync() { return await ClientCache.GetOrCreateAsync( - TencentCloudClientCacheItem.CalculateCacheKey(CurrentTenant), + TencentCloudClientCacheItem.CalculateCacheKey("client"), async (_) => { var secretId = await SettingProvider.GetOrNullAsync(TencentCloudSettingNames.SecretId); var secretKey = await SettingProvider.GetOrNullAsync(TencentCloudSettingNames.SecretKey); var endpoint = await SettingProvider.GetOrNullAsync(TencentCloudSettingNames.EndPoint); + var durationSecond = await SettingProvider.GetAsync(TencentCloudSettingNames.DurationSecond, 3600); Check.NotNullOrWhiteSpace(secretId, TencentCloudSettingNames.SecretId); Check.NotNullOrWhiteSpace(secretKey, TencentCloudSettingNames.SecretKey); @@ -56,6 +53,7 @@ public abstract class AbstractTencentCloudClientFactory SecretKey = secretKey, // 连接区域 EndPoint = endpoint, + DurationSecond = durationSecond, HttpMethod = method, WebProxy = webProxy, Timeout = timeout, @@ -67,16 +65,13 @@ public abstract class AbstractTencentCloudClientFactory public abstract class AbstractTencentCloudClientFactory { protected IMemoryCache ClientCache { get; } - protected ICurrentTenant CurrentTenant { get; } protected ISettingProvider SettingProvider { get; } public AbstractTencentCloudClientFactory( IMemoryCache clientCache, - ICurrentTenant currentTenant, ISettingProvider settingProvider) { ClientCache = clientCache; - CurrentTenant = currentTenant; SettingProvider = settingProvider; } @@ -92,7 +87,7 @@ public abstract class AbstractTencentCloudClientFactory protected async virtual Task GetClientCacheItemAsync() { return await ClientCache.GetOrCreateAsync( - TencentCloudClientCacheItem.CalculateCacheKey(CurrentTenant), + TencentCloudClientCacheItem.CalculateCacheKey("client"), async (_) => { var secretId = await SettingProvider.GetOrNullAsync(TencentCloudSettingNames.SecretId); diff --git a/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent/LINGYUN/Abp/Tencent/TencentCloudClientCacheItem.cs b/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent/LINGYUN/Abp/Tencent/TencentCloudClientCacheItem.cs index 16a353e99..142716a1b 100644 --- a/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent/LINGYUN/Abp/Tencent/TencentCloudClientCacheItem.cs +++ b/aspnet-core/modules/cloud-tencent/LINGYUN.Abp.Tencent/LINGYUN/Abp/Tencent/TencentCloudClientCacheItem.cs @@ -1,10 +1,8 @@ -using Volo.Abp.MultiTenancy; - -namespace LINGYUN.Abp.Tencent; +namespace LINGYUN.Abp.Tencent; public class TencentCloudClientCacheItem { - public const string CacheKeyFormat = "pn:{0},n:tenant-cloud"; + public const string CacheKeyFormat = "pn:tenant-cloud,n:{0}"; public string SecretId { get; set; } public string SecretKey { get; set; } public string EndPoint { get; set; } @@ -14,8 +12,8 @@ public class TencentCloudClientCacheItem public int Timeout { get; set; } public int DurationSecond { get; set; } - public static string CalculateCacheKey(ICurrentTenant currentTenant) + public static string CalculateCacheKey(string provider) { - return string.Format(CacheKeyFormat, currentTenant.IsAvailable ? currentTenant.GetId().ToString() : "global"); + return string.Format(CacheKeyFormat, provider); } } diff --git a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/ConnectionStringInvalidator.cs b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/ConnectionStringInvalidator.cs index 055480eaf..3a8d57cc5 100644 --- a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/ConnectionStringInvalidator.cs +++ b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/ConnectionStringInvalidator.cs @@ -20,16 +20,24 @@ public class ConnectionStringInvalidator : public async virtual Task HandleEventAsync(ConnectionStringCreatedEventData eventData) { // 需要考虑三种情形下的缓存键 - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(null, eventData.TenantName), considerUow: true); - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(eventData.TenantId, null), considerUow: true); - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(eventData.TenantId, eventData.TenantName), considerUow: true); + var keys = new string[] + { + TenantCacheItem.CalculateCacheKey(null, eventData.TenantName), + TenantCacheItem.CalculateCacheKey(eventData.TenantId, null), + TenantCacheItem.CalculateCacheKey(eventData.TenantId, eventData.TenantName), + }; + await Cache.RemoveManyAsync(keys, considerUow: true); } public async virtual Task HandleEventAsync(ConnectionStringDeletedEventData eventData) { // 需要考虑三种情形下的缓存键 - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(null, eventData.TenantName), considerUow: true); - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(eventData.TenantId, null), considerUow: true); - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(eventData.TenantId, eventData.TenantName), considerUow: true); + var keys = new string[] + { + TenantCacheItem.CalculateCacheKey(null, eventData.TenantName), + TenantCacheItem.CalculateCacheKey(eventData.TenantId, null), + TenantCacheItem.CalculateCacheKey(eventData.TenantId, eventData.TenantName), + }; + await Cache.RemoveManyAsync(keys, considerUow: true); } } diff --git a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantCacheItemInvalidator.cs b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantCacheItemInvalidator.cs index d6f365171..0c322fe57 100644 --- a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantCacheItemInvalidator.cs +++ b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantCacheItemInvalidator.cs @@ -18,11 +18,15 @@ public class TenantCacheItemInvalidator : ILocalEventHandler eventData) { - // 需要考虑三种情形下的缓存键 - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(null, eventData.Entity.Name), considerUow: true); - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(eventData.Entity.Id, null), considerUow: true); - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(eventData.Entity.Id, eventData.Entity.Name), considerUow: true); - // 同时移除租户版本缓存 - await Cache.RemoveAsync(EditionCacheItem.CalculateCacheKey(eventData.Entity.Id), considerUow: true); + var keys = new string[] + { + TenantCacheItem.CalculateCacheKey(null, eventData.Entity.Name), + TenantCacheItem.CalculateCacheKey(eventData.Entity.Id, null), + TenantCacheItem.CalculateCacheKey(eventData.Entity.Id, eventData.Entity.Name), + + // 同时移除租户版本缓存 + EditionCacheItem.CalculateCacheKey(eventData.Entity.Id) + }; + await Cache.RemoveManyAsync(keys, considerUow: true); } }