mirror of https://github.com/EasyAbp/EShop.git
committed by
GitHub
5 changed files with 83 additions and 11 deletions
@ -0,0 +1,46 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities.Events.Distributed; |
||||
|
using Volo.Abp.EventBus.Distributed; |
||||
|
using Volo.Abp.Uow; |
||||
|
|
||||
|
namespace EasyAbp.EShop.Products.Products; |
||||
|
|
||||
|
public class ProductCacheInvalidator : |
||||
|
IDistributedEventHandler<EntityUpdatedEto<ProductEto>>, |
||||
|
IDistributedEventHandler<EntityDeletedEto<ProductEto>>, |
||||
|
ITransientDependency |
||||
|
{ |
||||
|
protected IDistributedCache<ProductCacheItem, Guid> DistributedCache { get; } |
||||
|
protected IUnitOfWorkManager UnitOfWorkManager { get; } |
||||
|
|
||||
|
public ProductCacheInvalidator( |
||||
|
IDistributedCache<ProductCacheItem, Guid> distributedCache, |
||||
|
IUnitOfWorkManager unitOfWorkManager) |
||||
|
{ |
||||
|
DistributedCache = distributedCache; |
||||
|
UnitOfWorkManager = unitOfWorkManager; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task HandleEventAsync(EntityUpdatedEto<ProductEto> eventData) |
||||
|
{ |
||||
|
await DistributedCache.RemoveAsync(eventData.Entity.Id); |
||||
|
|
||||
|
UnitOfWorkManager.Current.OnCompleted(async () => |
||||
|
{ |
||||
|
await DistributedCache.RemoveAsync(eventData.Entity.Id); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task HandleEventAsync(EntityDeletedEto<ProductEto> eventData) |
||||
|
{ |
||||
|
await DistributedCache.RemoveAsync(eventData.Entity.Id); |
||||
|
|
||||
|
UnitOfWorkManager.Current.OnCompleted(async () => |
||||
|
{ |
||||
|
await DistributedCache.RemoveAsync(eventData.Entity.Id); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System; |
||||
|
using EasyAbp.EShop.Products.Products.Dtos; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace EasyAbp.EShop.Products.Products; |
||||
|
|
||||
|
public class ProductCacheItem : ProductDto, IMultiTenant |
||||
|
{ |
||||
|
public Guid? TenantId { get; set; } |
||||
|
} |
||||
Loading…
Reference in new issue