< Summary

Information
Class: Elsa.Caching.Services.CacheManager
Assembly: Elsa.Caching
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Caching/Services/CacheManager.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 44
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_CachingOptions()100%11100%
GetToken(...)100%11100%
TriggerTokenAsync(...)100%11100%
<FindOrCreateAsync()100%11100%
FindOrCreateAsync()100%11100%
<GetOrCreateAsync()100%11100%
GetOrCreateAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Caching/Services/CacheManager.cs

#LineLine coverage
 1using Elsa.Caching.Options;
 2using Microsoft.Extensions.Caching.Memory;
 3using Microsoft.Extensions.Options;
 4using Microsoft.Extensions.Primitives;
 5
 6namespace Elsa.Caching.Services;
 7
 8/// <inheritdoc />
 79public class CacheManager(IMemoryCache memoryCache, IChangeTokenSignaler changeTokenSignaler, IOptions<CachingOptions> o
 10{
 11    /// <inheritdoc />
 726612    public IOptions<CachingOptions> CachingOptions => options;
 13
 14    /// <inheritdoc />
 15    public IChangeToken GetToken(string key)
 16    {
 737417        return changeTokenSignaler.GetToken(key);
 18    }
 19
 20    /// <inheritdoc />
 21    public ValueTask TriggerTokenAsync(string key, CancellationToken cancellationToken = default)
 22    {
 522123        return changeTokenSignaler.TriggerTokenAsync(key, cancellationToken);
 24    }
 25
 26    /// <inheritdoc />
 27    public async Task<TItem?> FindOrCreateAsync<TItem>(object key, Func<ICacheEntry, Task<TItem>> factory)
 28    {
 1405929        return await memoryCache.GetOrCreateAsync(key, async entry => await factory(entry));
 719730    }
 31
 32    /// <summary>
 33    /// Retrieves a cached item by the specified key or creates a new one using the provided factory function.
 34    /// </summary>
 35    /// <param name="key">The key used to identify the cached item.</param>
 36    /// <param name="factory">A factory function that provides the value to be cached if it does not already exist.</par
 37    /// <typeparam name="TItem">The type of the item to retrieve or create.</typeparam>
 38    /// <returns>The cached or newly created item.</returns>
 39    /// <exception cref="InvalidOperationException">Thrown if the factory function returns null.</exception>
 40    public async Task<TItem> GetOrCreateAsync<TItem>(object key, Func<ICacheEntry, Task<TItem>> factory)
 41    {
 147042        return await memoryCache.GetOrCreateAsync(key, async entry => await factory(entry)) ?? throw new InvalidOperatio
 106443    }
 44}