mirror of https://github.com/abpframework/abp.git
3 changed files with 61 additions and 11 deletions
@ -0,0 +1,37 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities.Events; |
||||
|
using Volo.Abp.EventBus; |
||||
|
|
||||
|
namespace Volo.CmsKit.Pages; |
||||
|
|
||||
|
public class PageChangedHandler : |
||||
|
ILocalEventHandler<EntityCreatedEventData<Page>>, |
||||
|
ILocalEventHandler<EntityUpdatedEventData<Page>>, |
||||
|
ITransientDependency |
||||
|
|
||||
|
{ |
||||
|
protected IDistributedCache<PageCacheItem, PageCacheKey> Cache { get; } |
||||
|
|
||||
|
public PageChangedHandler(IDistributedCache<PageCacheItem, PageCacheKey> cache) |
||||
|
{ |
||||
|
Cache = cache; |
||||
|
} |
||||
|
|
||||
|
public Task RemoveFromCacheAsync(string slug) |
||||
|
{ |
||||
|
return Cache.RemoveAsync(new PageCacheKey(slug)); |
||||
|
} |
||||
|
|
||||
|
public Task HandleEventAsync(EntityCreatedEventData<Page> eventData) |
||||
|
{ |
||||
|
return RemoveFromCacheAsync(eventData.Entity.Slug); |
||||
|
} |
||||
|
|
||||
|
public Task HandleEventAsync(EntityUpdatedEventData<Page> eventData) |
||||
|
{ |
||||
|
return RemoveFromCacheAsync(eventData.Entity.Slug); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
namespace Volo.CmsKit.Pages; |
||||
|
public class PageCacheKey |
||||
|
{ |
||||
|
public PageCacheKey(string slug) |
||||
|
{ |
||||
|
Slug = slug; |
||||
|
} |
||||
|
|
||||
|
public string Slug { get; set; } |
||||
|
|
||||
|
public override string ToString() |
||||
|
{ |
||||
|
return $"Page_{Slug}"; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue