using Microsoft.Extensions.Caching.Memory; namespace MicCheck.Api.Features; public class FlagCache(IMemoryCache cache) { private static readonly TimeSpan CacheDuration = TimeSpan.FromSeconds(60); public IReadOnlyList? Get(int environmentId) { cache.TryGetValue(CacheKey(environmentId), out IReadOnlyList? flags); return flags; } public void Set(int environmentId, IReadOnlyList flags) => cache.Set(CacheKey(environmentId), flags, CacheDuration); public void Invalidate(int environmentId) => cache.Remove(CacheKey(environmentId)); private static string CacheKey(int environmentId) => $"flags:{environmentId}"; }