using Elsa.Caching;
using Elsa.Mediator.Contracts;
using Elsa.Workflows.Runtime.Notifications;
using Elsa.Workflows.Runtime.Stores;
using JetBrains.Annotations;
namespace Elsa.Workflows.Runtime.Handlers;
///
/// A notification handler that invalidates triggers cache when workflow definitions are refreshed.
///
///
/// The class implements the INotificationHandler interface and is responsible for handling WorkflowDefinitionsRefreshed notifications.
/// When a WorkflowDefinitionsRefreshed notification is received, the HandleAsync method is called to invalidate the triggers cache.
/// The cache is invalidated by calling the TriggerTokenAsync method of the ICacheManager passed to the class constructor.
///
[UsedImplicitly]
public class InvalidateTriggersCache(ICacheManager cacheManager) :
INotificationHandler,
INotificationHandler
{
///
public Task HandleAsync(WorkflowDefinitionsRefreshed notification, CancellationToken cancellationToken)
{
return cacheManager.TriggerTokenAsync(CachingTriggerStore.CacheInvalidationTokenKey, cancellationToken).AsTask();
}
///
public async Task HandleAsync(WorkflowDefinitionsReloaded notification, CancellationToken cancellationToken)
{
await cacheManager.TriggerTokenAsync(CachingTriggerStore.CacheInvalidationTokenKey, cancellationToken);
}
}