<PackageReference Include="Polly" Version="8.0.0-alpha.3" />

AsyncCachePolicy

public class AsyncCachePolicy : AsyncPolicy
using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace Polly.Caching { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class AsyncCachePolicy : AsyncPolicy { private readonly IAsyncCacheProvider _asyncCacheProvider; private readonly ITtlStrategy _ttlStrategy; private readonly Func<Context, string> _cacheKeyStrategy; private readonly Action<Context, string> _onCacheGet; private readonly Action<Context, string> _onCacheMiss; private readonly Action<Context, string> _onCachePut; [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1, 1, 1 })] private readonly Action<Context, string, Exception> _onCacheGetError; [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1, 1, 1 })] private readonly Action<Context, string, Exception> _onCachePutError; internal AsyncCachePolicy(IAsyncCacheProvider asyncCacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string> onCacheGet, Action<Context, string> onCacheMiss, Action<Context, string> onCachePut, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1, 1, 1 })] Action<Context, string, Exception> onCacheGetError, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 1, 1, 1 })] Action<Context, string, Exception> onCachePutError) : base((PolicyBuilder)null) { _asyncCacheProvider = asyncCacheProvider; _ttlStrategy = ttlStrategy; _cacheKeyStrategy = cacheKeyStrategy; _onCacheGet = onCacheGet; _onCachePut = onCachePut; _onCacheMiss = onCacheMiss; _onCacheGetError = onCacheGetError; _onCachePutError = onCachePutError; } 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<[System.Runtime.CompilerServices.Nullable(0)] 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); } } }