// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using System.Threading.Tasks; namespace Squidex.Infrastructure.Caching { public static class LocalCacheExtensions { public static async Task GetOrCreateAsync(this ILocalCache cache, object key, Func> task) { if (cache.TryGetValue(key, out var value)) { if (value is T typed) { return typed; } else { return default!; } } var result = await task(); cache.Add(key, result); return result; } } }