diff --git a/ZR.Common/Cache/CacheHelper.cs b/ZR.Common/Cache/CacheHelper.cs index 0fc66258..7b1511a3 100644 --- a/ZR.Common/Cache/CacheHelper.cs +++ b/ZR.Common/Cache/CacheHelper.cs @@ -1,5 +1,8 @@ using Microsoft.Extensions.Caching.Memory; using System; +using System.Collections.Generic; +using System.Collections; +using System.Reflection; namespace ZR.Common { @@ -106,6 +109,25 @@ namespace ZR.Common { Cache.Remove(key); } + + + /// + /// 获取所有缓存键 + /// + /// + public static List GetCacheKeys() + { + const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic; + var entries = Cache.GetType().GetField("_entries", flags).GetValue(Cache); + var keys = new List(); + if (entries is not IDictionary cacheItems) return keys; + foreach (DictionaryEntry cacheItem in cacheItems) + { + keys.Add(cacheItem.Key.ToString()); + Console.WriteLine(cacheItem.Key); + } + return keys; + } } }