public static async Task <T?> GetOrSetJsonObjectAsync <T>(this IDistributedCache cache, string key, Func <Task <T?> > valueFactory, DistributedCacheEntryOptions entryOptions, JsonSerializerOptions?serializerOptions = null, CancellationToken token = default) where T : class { var cached = await cache.GetJsonObjectAsync <T>(key, serializerOptions, token); if (cached != null) { return(cached); } var value = await valueFactory(); if (value != null) { await cache.SetJsonObjectAsync(key, value, entryOptions, serializerOptions, token); } return(value); }
public static Task <T?> GetJsonObjectAsync <T>(this IDistributedCache cache, string key, CancellationToken token = default) where T : class { return(cache.GetJsonObjectAsync <T>(key, null, token)); }