mirror of https://github.com/abpframework/abp.git
7 changed files with 117 additions and 19 deletions
@ -0,0 +1,25 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.SettingManagement |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class SettingCacheItem |
||||
|
{ |
||||
|
public string Value { get; set; } |
||||
|
|
||||
|
public SettingCacheItem() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public SettingCacheItem(string value) |
||||
|
{ |
||||
|
Value = value; |
||||
|
} |
||||
|
|
||||
|
public static string CalculateCacheKey(string name, string providerName, string providerKey) |
||||
|
{ |
||||
|
return "pn:" + providerName + ",pk:" + providerKey + ",n:" + name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities.Events; |
||||
|
using Volo.Abp.EventBus; |
||||
|
|
||||
|
namespace Volo.Abp.SettingManagement |
||||
|
{ |
||||
|
public class SettingCacheItemInvalidator : ILocalEventHandler<EntityChangedEventData<Setting>>, ITransientDependency |
||||
|
{ |
||||
|
protected IDistributedCache<SettingCacheItem> Cache { get; } |
||||
|
|
||||
|
public SettingCacheItemInvalidator(IDistributedCache<SettingCacheItem> cache) |
||||
|
{ |
||||
|
Cache = cache; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task HandleEventAsync(EntityChangedEventData<Setting> eventData) |
||||
|
{ |
||||
|
var cacheKey = CalculateCacheKey( |
||||
|
eventData.Entity.Name, |
||||
|
eventData.Entity.ProviderName, |
||||
|
eventData.Entity.ProviderKey |
||||
|
); |
||||
|
|
||||
|
await Cache.RemoveAsync(cacheKey); |
||||
|
} |
||||
|
|
||||
|
protected virtual string CalculateCacheKey(string name, string providerName, string providerKey) |
||||
|
{ |
||||
|
return SettingCacheItem.CalculateCacheKey(name, providerName, providerKey); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue