Use considerUow in CacheItemInvalidator.

pull/9943/head
maliming 4 years ago
parent 50cf7cd729
commit 03ba9ec65e

@ -6,7 +6,7 @@ using Volo.Abp.EventBus;
namespace Volo.Abp.FeatureManagement
{
public class FeatureValueCacheItemInvalidator :
public class FeatureValueCacheItemInvalidator :
ILocalEventHandler<EntityChangedEventData<FeatureValue>>,
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)

@ -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<FeatureValueCacheItem> _cache;
private IFeatureValueRepository _featureValueRepository;
private IFeatureManagementStore _featureManagementStore;
private ICurrentTenant _currentTenant;
public FeatureValueCacheItemInvalidator_Tests()
{
_cache = GetRequiredService<IDistributedCache<FeatureValueCacheItem>>();
_featureValueRepository = GetRequiredService<IFeatureValueRepository>();
_featureManagementStore = GetRequiredService<IFeatureManagementStore>();
_currentTenant = GetRequiredService<ICurrentTenant>();
}
[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();
}
}
}
}

@ -31,7 +31,7 @@ namespace Volo.Abp.IdentityServer
public virtual async Task HandleEventAsync(EntityChangedEventData<Client> eventData)
{
var clientCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Client>>();
await clientCache.RemoveAsync(eventData.Entity.ClientId);
await clientCache.RemoveAsync(eventData.Entity.ClientId, considerUow: true);
var corsCache = ServiceProvider.GetRequiredService<IDistributedCache<AllowedCorsOriginsCacheItem>>();
await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);

@ -17,8 +17,8 @@ namespace Volo.Abp.TenantManagement
public virtual async Task HandleEventAsync(EntityChangedEventData<Tenant> 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);
}
}
}

Loading…
Cancel
Save