Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Getting Started with EricksonLopez.Caching

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
Terminal window
dotnet add package EricksonLopez.Caching.Redis --version 1.0.0
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);
}
}