< Summary

Information
Class: Elsa.Http.Services.CachingHttpWorkflowLookupService
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/CachingHttpWorkflowLookupService.cs
Line coverage
96%
Covered lines: 30
Uncovered lines: 1
Coverable lines: 31
Total lines: 46
Line coverage: 96.7%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
FindWorkflowAsync()50%44100%
<FindWorkflowAsync()75%4492.85%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/CachingHttpWorkflowLookupService.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using JetBrains.Annotations;
 3using Microsoft.Extensions.Caching.Memory;
 4
 5namespace Elsa.Http.Services;
 6
 7/// <summary>
 8/// Represents a caching implementation of the IHttpWorkflowLookupService that retrieves workflows using HTTP workflow l
 9/// </summary>
 10[UsedImplicitly]
 27011public class CachingHttpWorkflowLookupService(
 27012    IHttpWorkflowLookupService decoratedService,
 27013    IHttpWorkflowsCacheManager cacheManager,
 27014    ITenantAccessor tenantAccessor) : IHttpWorkflowLookupService
 15{
 16    /// <inheritdoc />
 17    public async Task<HttpWorkflowLookupResult?> FindWorkflowAsync(string bookmarkHash, CancellationToken cancellationTo
 18    {
 27019        var tenant = tenantAccessor.Tenant;
 27020        var tenantId = tenant?.Id;
 27021        var tenantIdPrefix = !string.IsNullOrEmpty(tenantId) ? $"{tenantId}:" : string.Empty;
 27022        var key = $"{tenantIdPrefix}http-workflow:{bookmarkHash}";
 27023        var cache = cacheManager.Cache;
 27024        return await cache.GetOrCreateAsync(key, async entry =>
 27025        {
 22426            var cachingOptions = cache.CachingOptions.Value;
 22427            entry.SetSlidingExpiration(cachingOptions.CacheDuration);
 22428            entry.AddExpirationToken(cache.GetToken(cacheManager.GetTriggerChangeTokenKey(bookmarkHash)));
 27029
 22430            var result = await decoratedService.FindWorkflowAsync(bookmarkHash, cancellationToken);
 27031
 22432            if (result == null)
 633                return null;
 27034
 21835            if(result.WorkflowGraph == null)
 036                return result;
 27037
 21838            var workflowGraph = result.WorkflowGraph!;
 21839            var changeTokenKey = cacheManager.GetWorkflowChangeTokenKey(workflowGraph.Workflow.Identity.DefinitionId);
 21840            var changeToken = cache.GetToken(changeTokenKey);
 21841            entry.AddExpirationToken(changeToken);
 27042
 21843            return result;
 49444        });
 27045    }
 46}