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

AsyncGenericCacheProvider<TCacheFormat>

class AsyncGenericCacheProvider<TCacheFormat> : IAsyncCacheProvider<TCacheFormat>
Provides a strongly-typed wrapper over a non-generic CacheProviderAsync.
using System; using System.Threading; using System.Threading.Tasks; namespace Polly.Caching { internal class AsyncGenericCacheProvider<TCacheFormat> : IAsyncCacheProvider<TCacheFormat> { private readonly IAsyncCacheProvider _wrappedCacheProvider; internal AsyncGenericCacheProvider(IAsyncCacheProvider nonGenericCacheProvider) { if (nonGenericCacheProvider == null) throw new ArgumentNullException("nonGenericCacheProvider"); _wrappedCacheProvider = nonGenericCacheProvider; } async Task<(bool, TCacheFormat)> IAsyncCacheProvider<TCacheFormat>.TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) { (bool, object) obj = await this._wrappedCacheProvider.TryGetAsync(key, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); bool item = obj.Item1; object item2 = obj.Item2; return (item, (TCacheFormat)(item2 ?? ((object)default(TCacheFormat)))); } Task IAsyncCacheProvider<TCacheFormat>.PutAsync(string key, TCacheFormat value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) { return _wrappedCacheProvider.PutAsync(key, value, ttl, cancellationToken, continueOnCapturedContext); } } }