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; /// /// 设置缓存项 过期 /// 变动时 过期 /// public class SettingCacheItemInvalidator : ILocalEventHandler>, ITransientDependency { protected IDistributedCache Cache { get; } public SettingCacheItemInvalidator(IDistributedCache cache) { Cache = cache; } public virtual async Task HandleEventAsync(EntityChangedEventData 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); } }