From 374edc3771e0efab84164a65863d2a6fd0bfbc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 18 Sep 2022 00:58:44 +0300 Subject: [PATCH] Invalidate entity cache on change --- .../Domain/Entities/Caching/EntityCacheBase.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs index 6874878286..3f3b5fa42d 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheBase.cs +++ b/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 : - IEntityCache + IEntityCache, + ILocalEventHandler> where TEntity : Entity where TEntityCacheItem : class { @@ -37,4 +40,14 @@ public abstract class EntityCacheBase : } protected abstract TEntityCacheItem MapToCacheItem(TEntity entity); + + public async Task HandleEventAsync(EntityChangedEventData eventData) + { + if (eventData is EntityCreatedEventData) + { + return; + } + + await Cache.RemoveAsync(eventData.Entity.Id); + } } \ No newline at end of file