using Microsoft.Extensions.Caching.Memory; namespace EnvelopeGenerator.Extensions; public static class MemoryCacheExtensions { private static readonly Guid BaseId = Guid.NewGuid(); public static IDictionary GetEnumAsDictionary(this IMemoryCache memoryCache) where TEnum : Enum => memoryCache.GetOrCreate(BaseId + typeof(TEnum).FullName, _ => Enum.GetValues(typeof(TEnum)) .Cast() .ToDictionary(e => e.ToString(), e => Convert.ToInt32(e))) ?? throw new InvalidOperationException($"Failed to cache or retrieve enum dictionary for type '{typeof(TEnum).FullName}'."); }