.net 获取dotnet 7中的所有MemoryCache密钥

lnlaulya  于 2022-12-05  发布在  .NET
关注(0)|答案(1)|浏览(166)

如你所知他们删除了EntriesCollection在dotnet 7...
来源:https://github.com/dotnet/runtime/issues/63731
可以让我知道我如何访问所有的“内存缓存”键?
早些时候我用类似的东西得到了所有的钥匙
在内存缓存中,“条目集合”;
现在不工作了
我真的不知道该怎么办。

whlutmcx

whlutmcx1#

在.NET 7中,EntriesCollection属性已从MemoryCache类中删除。这意味着以前用于访问该高速缓存中的键的代码将不再起作用。
要在.NET 7中获取该高速缓存中的键,可以使用GetCacheKeys()方法,该方法返回一个包含缓存中的键的System.Collections.Generic.IEnumerable。下面是一个如何使用此方法获取缓存中的键的示例:

// Get the MemoryCache instance
var cache = MemoryCache.Default;
// Get the keys in the cache
var keys = cache.GetCacheKeys();
// Iterate over the keys and print them
foreach (var key in keys)
{
    Console.WriteLine(key);
}

相关问题