| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Management.Notifications; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Management.Handlers.Notifications; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// A workflow definition notifications handler for evicting the cache of the workflow definition service. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// This service listens for specific notifications and triggers cache invalidation operations accordingly. |
| | | 12 | | /// </remarks> |
| | | 13 | | [UsedImplicitly] |
| | 319 | 14 | | internal class EvictWorkflowDefinitionServiceCache(IWorkflowDefinitionCacheManager workflowDefinitionCacheManager) : |
| | | 15 | | INotificationHandler<WorkflowDefinitionDraftSaving>, |
| | | 16 | | INotificationHandler<WorkflowDefinitionPublishing>, |
| | | 17 | | INotificationHandler<WorkflowDefinitionRetracting>, |
| | | 18 | | INotificationHandler<WorkflowDefinitionDeleting>, |
| | | 19 | | INotificationHandler<WorkflowDefinitionsDeleting>, |
| | | 20 | | INotificationHandler<WorkflowDefinitionVersionsUpdating> |
| | | 21 | | { |
| | | 22 | | public Task HandleAsync(WorkflowDefinitionDraftSaving notification, CancellationToken cancellationToken) |
| | | 23 | | { |
| | 2 | 24 | | return workflowDefinitionCacheManager.EvictWorkflowDefinitionAsync(notification.WorkflowDefinition.DefinitionId, |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public Task HandleAsync(WorkflowDefinitionPublishing notification, CancellationToken cancellationToken) |
| | | 29 | | { |
| | 5 | 30 | | return workflowDefinitionCacheManager.EvictWorkflowDefinitionAsync(notification.WorkflowDefinition.DefinitionId, |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | public Task HandleAsync(WorkflowDefinitionRetracting notification, CancellationToken cancellationToken) |
| | | 35 | | { |
| | 0 | 36 | | return workflowDefinitionCacheManager.EvictWorkflowDefinitionAsync(notification.WorkflowDefinition.DefinitionId, |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | | 40 | | public Task HandleAsync(WorkflowDefinitionDeleting notification, CancellationToken cancellationToken) |
| | | 41 | | { |
| | 4 | 42 | | return workflowDefinitionCacheManager.EvictWorkflowDefinitionAsync(notification.DefinitionId, cancellationToken) |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <inheritdoc /> |
| | | 46 | | public async Task HandleAsync(WorkflowDefinitionsDeleting notification, CancellationToken cancellationToken) |
| | | 47 | | { |
| | 0 | 48 | | foreach (var definitionId in notification.DefinitionIds) |
| | 0 | 49 | | await workflowDefinitionCacheManager.EvictWorkflowDefinitionAsync(definitionId, cancellationToken); |
| | 0 | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <inheritdoc /> |
| | | 53 | | public async Task HandleAsync(WorkflowDefinitionVersionsUpdating notification, CancellationToken cancellationToken) |
| | | 54 | | { |
| | 0 | 55 | | foreach (var definition in notification.WorkflowDefinitions) |
| | 0 | 56 | | await workflowDefinitionCacheManager.EvictWorkflowDefinitionAsync(definition.DefinitionId, cancellationToken |
| | 0 | 57 | | } |
| | | 58 | | } |