Browse Source

Remove cache on unitofwork completed

pull/184/head
Jadyn 4 years ago
parent
commit
642ce1aa18
  1. 16
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalesPlans/FlashSalesPlanCacheInvalidator.cs

16
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalesPlans/FlashSalesPlanCacheInvalidator.cs

@ -4,20 +4,30 @@ using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events; using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus; using Volo.Abp.EventBus;
using Volo.Abp.Uow;
namespace EasyAbp.EShop.Plugins.FlashSales.FlashSalesPlans; namespace EasyAbp.EShop.Plugins.FlashSales.FlashSalesPlans;
public class FlashSalesPlanCacheInvalidator : ILocalEventHandler<EntityChangedEventData<FlashSalesPlan>>, ITransientDependency public class FlashSalesPlanCacheInvalidator : ILocalEventHandler<EntityChangedEventData<FlashSalesPlan>>, ITransientDependency
{ {
protected IDistributedCache<FlashSalesPlanCacheItem, Guid> DistributedCache { get; } protected IDistributedCache<FlashSalesPlanCacheItem, Guid> DistributedCache { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; }
public FlashSalesPlanCacheInvalidator(IDistributedCache<FlashSalesPlanCacheItem, Guid> distributedCache) public FlashSalesPlanCacheInvalidator(
IDistributedCache<FlashSalesPlanCacheItem, Guid> distributedCache,
IUnitOfWorkManager unitOfWorkManager)
{ {
DistributedCache = distributedCache; DistributedCache = distributedCache;
UnitOfWorkManager = unitOfWorkManager;
} }
public virtual async Task HandleEventAsync(EntityChangedEventData<FlashSalesPlan> eventData) public virtual Task HandleEventAsync(EntityChangedEventData<FlashSalesPlan> eventData)
{ {
await DistributedCache.RemoveAsync(eventData.Entity.Id); UnitOfWorkManager.Current.OnCompleted(async () =>
{
await DistributedCache.RemoveAsync(eventData.Entity.Id);
});
return Task.CompletedTask;
} }
} }

Loading…
Cancel
Save