Add `TenantConfigurationCacheItemInvalidator`.

pull/18412/head
maliming 1 year ago
parent 714b59a059
commit 037147ed47
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.MultiTenancy;
@ -18,20 +17,17 @@ public class TenantAppService : TenantManagementAppServiceBase, ITenantAppServic
protected ITenantRepository TenantRepository { get; }
protected ITenantManager TenantManager { get; }
protected IDistributedEventBus DistributedEventBus { get; }
protected IDistributedCache<TenantConfigurationCacheItem> TenantConfigurationCache { get; }
public TenantAppService(
ITenantRepository tenantRepository,
ITenantManager tenantManager,
IDataSeeder dataSeeder,
IDistributedEventBus distributedEventBus,
IDistributedCache<TenantConfigurationCacheItem> tenantConfigurationCache)
IDistributedEventBus distributedEventBus)
{
DataSeeder = dataSeeder;
TenantRepository = tenantRepository;
TenantManager = tenantManager;
DistributedEventBus = distributedEventBus;
TenantConfigurationCache = tenantConfigurationCache;
}
public virtual async Task<TenantDto> GetAsync(Guid id)
@ -103,13 +99,6 @@ public class TenantAppService : TenantManagementAppServiceBase, ITenantAppServic
{
var tenant = await TenantRepository.GetAsync(id);
await TenantConfigurationCache.RemoveManyAsync(
new[]
{
TenantConfigurationCacheItem.CalculateCacheKey(tenant.Id, null),
TenantConfigurationCacheItem.CalculateCacheKey(null, tenant.Name),
});
await TenantManager.ChangeNameAsync(tenant, input.Name);
tenant.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
@ -130,13 +119,6 @@ public class TenantAppService : TenantManagementAppServiceBase, ITenantAppServic
}
await TenantRepository.DeleteAsync(tenant);
await TenantConfigurationCache.RemoveManyAsync(
new[]
{
TenantConfigurationCacheItem.CalculateCacheKey(tenant.Id, null),
TenantConfigurationCacheItem.CalculateCacheKey(null, tenant.Name),
});
}
[Authorize(TenantManagementPermissions.Tenants.ManageConnectionStrings)]

@ -0,0 +1,42 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.TenantManagement;
public class TenantConfigurationCacheItemInvalidator :
ILocalEventHandler<EntityChangedEventData<Tenant>>,
ILocalEventHandler<EntityDeletedEventData<Tenant>>, ITransientDependency
{
protected IDistributedCache<TenantConfigurationCacheItem> Cache { get; }
public TenantConfigurationCacheItemInvalidator(IDistributedCache<TenantConfigurationCacheItem> cache)
{
Cache = cache;
}
public virtual async Task HandleEventAsync(EntityChangedEventData<Tenant> eventData)
{
await ClearCacheAsync(eventData.Entity.Id, eventData.Entity.Name);
}
public virtual async Task HandleEventAsync(EntityDeletedEventData<Tenant> eventData)
{
await ClearCacheAsync(eventData.Entity.Id, eventData.Entity.Name);
}
protected virtual async Task ClearCacheAsync(Guid? id, string name)
{
await Cache.RemoveManyAsync(
new[]
{
TenantConfigurationCacheItem.CalculateCacheKey(id, null),
TenantConfigurationCacheItem.CalculateCacheKey(null, name),
});
}
}
Loading…
Cancel
Save