| | | 1 | | using Elsa.Caching.Options; |
| | | 2 | | using Microsoft.Extensions.Caching.Memory; |
| | | 3 | | using Microsoft.Extensions.Options; |
| | | 4 | | using Microsoft.Extensions.Primitives; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Caching.Services; |
| | | 7 | | |
| | | 8 | | /// <inheritdoc /> |
| | 1 | 9 | | public class CacheManager(IMemoryCache memoryCache, IChangeTokenSignaler changeTokenSignaler, IOptions<CachingOptions> o |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | 3508 | 12 | | public IOptions<CachingOptions> CachingOptions => options; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public IChangeToken GetToken(string key) |
| | | 16 | | { |
| | 3714 | 17 | | return changeTokenSignaler.GetToken(key); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <inheritdoc /> |
| | | 21 | | public ValueTask TriggerTokenAsync(string key, CancellationToken cancellationToken = default) |
| | | 22 | | { |
| | 2673 | 23 | | return changeTokenSignaler.TriggerTokenAsync(key, cancellationToken); |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public async Task<TItem?> GetOrCreateAsync<TItem>(object key, Func<ICacheEntry, Task<TItem>> factory) |
| | | 28 | | { |
| | 7938 | 29 | | return await memoryCache.GetOrCreateAsync(key, async entry => await factory(entry)); |
| | 4430 | 30 | | } |
| | | 31 | | } |