<PackageReference Include="Polly" Version="7.0.1" />

AsyncCacheEngine

static class AsyncCacheEngine
using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; namespace Polly.Caching { public class AsyncCachePolicy : AsyncPolicy { private readonly IAsyncCacheProvider _asyncCacheProvider = asyncCacheProvider; private readonly ITtlStrategy _ttlStrategy = ttlStrategy; private readonly Func<Context, string> _cacheKeyStrategy = cacheKeyStrategy; private readonly Action<Context, string> _onCacheGet = onCacheGet; private readonly Action<Context, string> _onCacheMiss = onCacheMiss; private readonly Action<Context, string> _onCachePut = onCachePut; private readonly Action<Context, string, Exception> _onCacheGetError = onCacheGetError; private readonly Action<Context, string, Exception> _onCachePutError = onCachePutError; internal AsyncCachePolicy(IAsyncCacheProvider asyncCacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string> onCacheGet, Action<Context, string> onCacheMiss, Action<Context, string> onCachePut, Action<Context, string, Exception> onCacheGetError, Action<Context, string, Exception> onCachePutError) : base((PolicyBuilder)null) { } protected override Task ImplementationAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) { return action(context, cancellationToken); } [DebuggerStepThrough] protected override Task<TResult> ImplementationAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) { return AsyncCacheEngine.ImplementationAsync(_asyncCacheProvider.AsyncFor<TResult>(), _ttlStrategy.For<TResult>(), _cacheKeyStrategy, action, context, cancellationToken, continueOnCapturedContext, _onCacheGet, _onCacheMiss, _onCachePut, _onCacheGetError, _onCachePutError); } } }