如何在asp.net核心中检索“内存缓存"键的列表? [英] How to retrieve a list of Memory Cache keys in asp.net core?

查看:74
本文介绍了如何在asp.net核心中检索“内存缓存"键的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要简洁.是否可以列出.Net Core Web应用程序中内存缓存"中的所有注册键?

To be succinct. Is possible list all register keys from Memory Cache in the .Net Core Web Application?

我在IMemoryCache界面中找不到任何内容.

I didn't find anything in IMemoryCache interface.

推荐答案

当前,在 IMemoryCache 接口中没有这样的方法可以返回所有缓存键.根据此github问题的评论,我不认为将来会添加

Currently there is no such method in the IMemoryCache interface to return all the cache keys. As per this github issue comments, i do not think that would be added in the future.

引用 Eilons 注释

我怀疑是否可以使用,因为部分想法缓存是在您问一个问题后的片刻,答案可能已经改变.也就是说,假设您有答案那里有哪些键-稍后会清除缓存并列出您拥有的钥匙无效.

I think it's doubtful this would be available because part of the idea with caching is that mere moments after you ask it a question, the answer could have changed. That is, suppose you have the answer to which keys are there - a moment later the cache is purged and the list of keys you have is invalid.

如果您需要密钥,则应在将项目设置为缓存并在需要时使用它时,在应用程序中维护密钥列表.

If you need the keys, you should maintain the list of keys in your app while you set items to the cache and use that as needed.

这是另一个有用的github问题

Here is another useful github issue

会为MemoryCache提供GetEnumerator()吗?

这篇关于如何在asp.net核心中检索“内存缓存"键的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆