You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using NPin.Framework.SettingManagement.Domain.Entities;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.Domain.Entities.Events;
|
|
using Volo.Abp.EventBus;
|
|
|
|
namespace NPin.Framework.SettingManagement.Domain.Caching;
|
|
|
|
/// <summary>
|
|
/// 设置缓存项 过期
|
|
/// 变动时 过期
|
|
/// </summary>
|
|
public class SettingCacheItemInvalidator : ILocalEventHandler<EntityChangedEventData<SettingEntity>>,
|
|
ITransientDependency
|
|
{
|
|
protected IDistributedCache<SettingCacheItem> Cache { get; }
|
|
|
|
public SettingCacheItemInvalidator(IDistributedCache<SettingCacheItem> cache)
|
|
{
|
|
Cache = cache;
|
|
}
|
|
|
|
public virtual async Task HandleEventAsync(EntityChangedEventData<SettingEntity> eventData)
|
|
{
|
|
var entity = eventData.Entity;
|
|
var cacheKey = CalculateCacheKey(
|
|
entity.Name,
|
|
entity.ProviderName,
|
|
entity.ProviderKey);
|
|
|
|
await Cache.RemoveAsync(cacheKey, considerUow: true);
|
|
}
|
|
|
|
protected virtual string CalculateCacheKey(string name, string providerName, string providerKey)
|
|
{
|
|
return SettingCacheItem.CalculateCacheKey(name, providerName, providerKey);
|
|
}
|
|
} |