added IEventSubscriber amd EventDistributorHostedService to optimize event processing

This commit is contained in:
sbwalker
2023-05-31 09:36:32 -04:00
parent 0d5c3a3a0c
commit 7a21f96552
5 changed files with 114 additions and 46 deletions

View File

@ -0,0 +1,24 @@
using Microsoft.Extensions.Caching.Memory;
using Oqtane.Models;
using Oqtane.Shared;
namespace Oqtane.Infrastructure.EventSubscribers
{
public class CacheInvalidationEventSubscriber : IEventSubscriber
{
private readonly IMemoryCache _cache;
public CacheInvalidationEventSubscriber(IMemoryCache cache)
{
_cache = cache;
}
public void EntityChanged(SyncEvent syncEvent)
{
if (syncEvent.EntityName == "Site" && syncEvent.Action == SyncEventActions.Refresh)
{
_cache.Remove($"site:{syncEvent.TenantId}:{syncEvent.EntityId}");
}
}
}
}