| | | 1 | | using Elsa.Caching; |
| | | 2 | | using Elsa.Common.Models; |
| | | 3 | | using Elsa.Common.Multitenancy; |
| | | 4 | | using Elsa.Workflows.Management.Filters; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Management.Services; |
| | | 7 | | |
| | | 8 | | /// <inheritdoc /> |
| | 3 | 9 | | public class WorkflowDefinitionCacheManager(ICacheManager cache, IHasher hasher, ITenantAccessor tenantAccessor) : IWork |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | 2396 | 12 | | public ICacheManager Cache => cache; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | 2 | 15 | | public string CreateWorkflowDefinitionVersionCacheKey(string definitionId, VersionOptions versionOptions) => TenantP |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public string CreateWorkflowDefinitionFilterCacheKey(WorkflowDefinitionFilter filter) |
| | | 19 | | { |
| | 710 | 20 | | var hash = hasher.Hash(filter); |
| | 710 | 21 | | return TenantPrefix() + $"WorkflowDefinition:{hash}"; |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | 35 | 25 | | public string CreateWorkflowVersionCacheKey(string definitionId, VersionOptions versionOptions) => TenantPrefix() + |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | 1225 | 28 | | public string CreateWorkflowVersionCacheKey(string definitionVersionId) => TenantPrefix() + $"Workflow:{definitionVe |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public string CreateWorkflowFilterCacheKey(WorkflowDefinitionFilter filter) |
| | | 32 | | { |
| | 425 | 33 | | var hash = hasher.Hash(filter); |
| | 425 | 34 | | return TenantPrefix() + $"Workflow:{hash}"; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <inheritdoc /> |
| | 0 | 38 | | public string CreateWorkflowDefinitionVersionCacheKey(string definitionVersionId) => TenantPrefix() + $"WorkflowDefi |
| | | 39 | | |
| | | 40 | | /// <inheritdoc /> |
| | 2217 | 41 | | public string CreateWorkflowDefinitionChangeTokenKey(string definitionId) => TenantPrefix() + $"WorkflowChangeToken: |
| | | 42 | | |
| | | 43 | | /// <inheritdoc /> |
| | | 44 | | public async Task EvictWorkflowDefinitionAsync(string definitionId, CancellationToken cancellationToken = default) |
| | | 45 | | { |
| | 1555 | 46 | | var changeTokenKey = CreateWorkflowDefinitionChangeTokenKey(definitionId); |
| | 1555 | 47 | | await cache.TriggerTokenAsync(changeTokenKey, cancellationToken); |
| | 1555 | 48 | | } |
| | | 49 | | |
| | | 50 | | private string TenantPrefix() |
| | | 51 | | { |
| | 4614 | 52 | | var tenantId = tenantAccessor.TenantId; |
| | 4614 | 53 | | return string.IsNullOrEmpty(tenantId) ? string.Empty : $"{tenantId}:"; |
| | | 54 | | } |
| | | 55 | | } |