From 96c6bce9b3402506cd06d07fe0736a0d0467df7e Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Thu, 15 Sep 2022 10:38:19 +0800 Subject: [PATCH] different tenant cache keys may exist --- .../Tenants/ConnectionStringInvalidator.cs | 21 +++++++------------ .../Tenants/TenantCacheItemInvalidator.cs | 3 +++ 2 files changed, 11 insertions(+), 13 deletions(-) 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 84ce9f988..055480eaf 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 @@ -1,7 +1,4 @@ using LINGYUN.Abp.MultiTenancy; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; @@ -22,19 +19,17 @@ public class ConnectionStringInvalidator : public async virtual Task HandleEventAsync(ConnectionStringCreatedEventData eventData) { - await Cache.RemoveAsync( - TenantCacheItem.CalculateCacheKey( - eventData.TenantId, - eventData.TenantName), - considerUow: true); + // 需要考虑三种情形下的缓存键 + 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); } public async virtual Task HandleEventAsync(ConnectionStringDeletedEventData eventData) { - await Cache.RemoveAsync( - TenantCacheItem.CalculateCacheKey( - eventData.TenantId, - eventData.TenantName), - considerUow: true); + // 需要考虑三种情形下的缓存键 + 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); } } 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 617abb778..d6f365171 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,6 +18,9 @@ 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);