diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureValueCacheItemInvalidator.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureValueCacheItemInvalidator.cs index 63e207b1e7..42b2ef63ee 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureValueCacheItemInvalidator.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureValueCacheItemInvalidator.cs @@ -6,7 +6,7 @@ using Volo.Abp.EventBus; namespace Volo.Abp.FeatureManagement { - public class FeatureValueCacheItemInvalidator : + public class FeatureValueCacheItemInvalidator : ILocalEventHandler>, ITransientDependency { @@ -25,7 +25,7 @@ namespace Volo.Abp.FeatureManagement eventData.Entity.ProviderKey ); - await Cache.RemoveAsync(cacheKey); + await Cache.RemoveAsync(cacheKey, considerUow: true); } protected virtual string CalculateCacheKey(string name, string providerName, string providerKey) diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/FeatureValueCacheItemInvalidator_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/FeatureValueCacheItemInvalidator_Tests.cs index 890e94663b..6978b44d2a 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/FeatureValueCacheItemInvalidator_Tests.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/FeatureValueCacheItemInvalidator_Tests.cs @@ -5,6 +5,8 @@ using System.Threading.Tasks; using Shouldly; using Volo.Abp.Caching; using Volo.Abp.Features; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Settings; using Xunit; namespace Volo.Abp.FeatureManagement @@ -14,12 +16,13 @@ namespace Volo.Abp.FeatureManagement private IDistributedCache _cache; private IFeatureValueRepository _featureValueRepository; private IFeatureManagementStore _featureManagementStore; - + private ICurrentTenant _currentTenant; public FeatureValueCacheItemInvalidator_Tests() { _cache = GetRequiredService>(); _featureValueRepository = GetRequiredService(); _featureManagementStore = GetRequiredService(); + _currentTenant = GetRequiredService(); } [Fact] @@ -51,7 +54,45 @@ namespace Volo.Abp.FeatureManagement ) ) ).ShouldBeNull(); + } + + [Fact] + public async Task Cache_Should_Invalidator_WhenSettingChanged_Between_Tenant_And_Host() + { + var tenantId = Guid.NewGuid(); + + using (_currentTenant.Change(tenantId)) + { + // Arrange cache feature. + (await _featureManagementStore.GetOrNullAsync( + TestFeatureDefinitionProvider.SocialLogins, + EditionFeatureValueProvider.ProviderName, + TestEditionIds.Regular.ToString() + ) + ).ShouldNotBeNull(); + } + + using (_currentTenant.Change(null)) + { + await _featureManagementStore.SetAsync(TestFeatureDefinitionProvider.SocialLogins, + false.ToString(), + EditionFeatureValueProvider.ProviderName, + TestEditionIds.Regular.ToString()); + } + + using (_currentTenant.Change(tenantId)) + { + // Arrange cache feature. + (await _cache.GetAsync( + FeatureValueCacheItem.CalculateCacheKey( + TestFeatureDefinitionProvider.SocialLogins, + EditionFeatureValueProvider.ProviderName, + TestEditionIds.Regular.ToString() + ) + ) + ).ShouldBeNull(); + } } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs index 4db0dac9bb..48b2e0e730 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs @@ -31,7 +31,7 @@ namespace Volo.Abp.IdentityServer public virtual async Task HandleEventAsync(EntityChangedEventData eventData) { var clientCache = ServiceProvider.GetRequiredService>(); - await clientCache.RemoveAsync(eventData.Entity.ClientId); + await clientCache.RemoveAsync(eventData.Entity.ClientId, considerUow: true); var corsCache = ServiceProvider.GetRequiredService>(); await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantCacheItemInvalidator.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantCacheItemInvalidator.cs index 0416dd8df2..084b816276 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantCacheItemInvalidator.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantCacheItemInvalidator.cs @@ -17,8 +17,8 @@ namespace Volo.Abp.TenantManagement public virtual async Task HandleEventAsync(EntityChangedEventData eventData) { - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(eventData.Entity.Id, null)); - await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(null, eventData.Entity.Name)); + await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(eventData.Entity.Id, null), considerUow: true); + await Cache.RemoveAsync(TenantCacheItem.CalculateCacheKey(null, eventData.Entity.Name), considerUow: true); } } }