Browse Source

Invalidate entity cache on change

pull/14055/head
Halil İbrahim Kalkan 4 years ago
parent
commit
374edc3771
  1. 15
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs

15
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs

@ -1,11 +1,14 @@
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus;
namespace Volo.Abp.Domain.Entities.Caching;
public abstract class EntityCacheBase<TEntity, TEntityCacheItem, TKey> :
IEntityCache<TEntityCacheItem, TKey>
IEntityCache<TEntityCacheItem, TKey>,
ILocalEventHandler<EntityChangedEventData<TEntity>>
where TEntity : Entity<TKey>
where TEntityCacheItem : class
{
@ -37,4 +40,14 @@ public abstract class EntityCacheBase<TEntity, TEntityCacheItem, TKey> :
}
protected abstract TEntityCacheItem MapToCacheItem(TEntity entity);
public async Task HandleEventAsync(EntityChangedEventData<TEntity> eventData)
{
if (eventData is EntityCreatedEventData<TEntity>)
{
return;
}
await Cache.RemoveAsync(eventData.Entity.Id);
}
}
Loading…
Cancel
Save