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

AsyncCachePolicy<TResult>

public class AsyncCachePolicy<TResult> : AsyncPolicy<TResult>
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(new byte[] { 0, 1 })] public class AsyncCachePolicy<[System.Runtime.CompilerServices.Nullable(2)] TResult> : AsyncPolicy<TResult> { private readonly ITtlStrategy<TResult> _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; private readonly IAsyncCacheProvider<TResult> _asyncCacheProvider; internal AsyncCachePolicy(IAsyncCacheProvider<TResult> asyncCacheProvider, ITtlStrategy<TResult> 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<TResult>)null) { _asyncCacheProvider = asyncCacheProvider; _ttlStrategy = ttlStrategy; _cacheKeyStrategy = cacheKeyStrategy; _onCacheGet = onCacheGet; _onCachePut = onCachePut; _onCacheMiss = onCacheMiss; _onCacheGetError = onCacheGetError; _onCachePutError = onCachePutError; } [DebuggerStepThrough] protected override Task<TResult> ImplementationAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) { return AsyncCacheEngine.ImplementationAsync<TResult>(_asyncCacheProvider, _ttlStrategy, _cacheKeyStrategy, action, context, cancellationToken, continueOnCapturedContext, _onCacheGet, _onCacheMiss, _onCachePut, _onCacheGetError, _onCachePutError); } } }