From b7386d0fb71e547a9f220469ad264fdc3ae33d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Fri, 3 Mar 2023 21:11:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=BC=93=E5=AD=98key=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Common/Cache/CacheHelper.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ZR.Common/Cache/CacheHelper.cs b/ZR.Common/Cache/CacheHelper.cs index 0fc6625..7b1511a 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; + } } }