Getting Started with EricksonLopez.Caching
L2StableNuGet: v1.0.0Local HEAD: v2.0.0AOT: Full
Install EricksonLopez.Caching (1.0.0 on NuGet) for in-memory, hybrid, and tenant-partitioned caching, plus EricksonLopez.Caching.Redis (1.0.0) for distributed Redis storage.
dotnet add package EricksonLopez.Caching --version 1.0.0<PackageReference Include="EricksonLopez.Caching" Version="1.0.0" /><PackageVersion Include="EricksonLopez.Caching" Version="1.0.0" />dotnet add package EricksonLopez.Caching.Redis --version 1.0.0Quick Start: MemoryCacheProvider & GetOrCreateAsync
Section titled “Quick Start: MemoryCacheProvider & GetOrCreateAsync”using System;using System.Threading;using System.Threading.Tasks;using EricksonLopez.Caching;using EricksonLopez.Result;
namespace Example.CachingDocs;
public static class CachingQuickStart{ public static async Task<Result<string>> GetOrLoadAsync(CancellationToken ct = default) { using var cache = new MemoryCacheProvider(); var options = new CacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5), FailSafeMaxStale = TimeSpan.FromMinutes(30), Tags = new[] { "catalog", "product:42" } };
return await cache.GetOrCreateAsync( key: "products:sku:42", factory: static _ => Task.FromResult("Widget-42"), options: options, cancellationToken: ct); }}