Squash and merge of version-0.1 Co-authored-by: James Wampler <james@wamp.dev> Co-committed-by: James Wampler <james@wamp.dev>
23 lines
737 B
C#
Executable File
23 lines
737 B
C#
Executable File
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
namespace MicCheck.Api.Features;
|
|
|
|
public class FlagCache(IMemoryCache cache)
|
|
{
|
|
private static readonly TimeSpan CacheDuration = TimeSpan.FromSeconds(60);
|
|
|
|
public IReadOnlyList<FeatureStateResult>? Get(int environmentId)
|
|
{
|
|
cache.TryGetValue(CacheKey(environmentId), out IReadOnlyList<FeatureStateResult>? flags);
|
|
return flags;
|
|
}
|
|
|
|
public void Set(int environmentId, IReadOnlyList<FeatureStateResult> flags)
|
|
=> cache.Set(CacheKey(environmentId), flags, CacheDuration);
|
|
|
|
public void Invalidate(int environmentId)
|
|
=> cache.Remove(CacheKey(environmentId));
|
|
|
|
private static string CacheKey(int environmentId) => $"flags:{environmentId}";
|
|
}
|