namespace Kit.Helpers.Cache { using Microsoft.Extensions.Caching.Memory; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; public static class MemoryCacheExtensions { private static readonly Func GetEntriesCollection = Delegate.CreateDelegate( typeof(Func), typeof(MemoryCache).GetProperty("EntriesCollection", BindingFlags.NonPublic | BindingFlags.Instance).GetGetMethod(true), throwOnBindFailure: true) as Func; public static IEnumerable GetKeys(this IMemoryCache memoryCache) => ((IDictionary)GetEntriesCollection((MemoryCache)memoryCache)).Keys; public static IEnumerable GetKeys(this IMemoryCache memoryCache) => GetKeys(memoryCache).OfType(); } }