elsa-core/src/modules/Elsa.Workflows.Runtime/Handlers/InvalidateTriggersCache.cs
MariusVuscanNx feb7da4d28
Implemented workflows reload endpoint (#5732)
* Implemented workflows reload endpoint

* Added componenent tests for reload

* Adjusted cache handling

* Made the refresh endpoint return refreshed and not found definitions

* Update test/component/Elsa.Workflows.ComponentTests/Scenarios/WorkflowDefinitionReload/RemoveReloadWorkflowTests.cs

Fix typo

Co-authored-by: raymonddenhaan <155616759+raymonddenhaan@users.noreply.github.com>

---------

Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
Co-authored-by: raymonddenhaan <155616759+raymonddenhaan@users.noreply.github.com>
2024-07-12 08:35:46 +02:00

33 lines
1.5 KiB
C#

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;
/// <summary>
/// A notification handler that invalidates triggers cache when workflow definitions are refreshed.
/// </summary>
/// <remarks>
/// The class implements the <c>INotificationHandler</c> interface and is responsible for handling <c>WorkflowDefinitionsRefreshed</c> notifications.
/// When a <c>WorkflowDefinitionsRefreshed</c> notification is received, the <c>HandleAsync</c> method is called to invalidate the triggers cache.
/// The cache is invalidated by calling the <c>TriggerTokenAsync</c> method of the <c>ICacheManager</c> passed to the class constructor.
/// </remarks>
[UsedImplicitly]
public class InvalidateTriggersCache(ICacheManager cacheManager) :
INotificationHandler<WorkflowDefinitionsRefreshed>,
INotificationHandler<WorkflowDefinitionsReloaded>
{
/// <inheritdoc />
public Task HandleAsync(WorkflowDefinitionsRefreshed notification, CancellationToken cancellationToken)
{
return cacheManager.TriggerTokenAsync(CachingTriggerStore.CacheInvalidationTokenKey, cancellationToken).AsTask();
}
/// <inheritdoc />
public async Task HandleAsync(WorkflowDefinitionsReloaded notification, CancellationToken cancellationToken)
{
await cacheManager.TriggerTokenAsync(CachingTriggerStore.CacheInvalidationTokenKey, cancellationToken);
}
}