C# 如何确定 ASP.Net 缓存的总大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/344210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:57:20  来源:igfitidea点击:

How to determine total size of ASP.Net cache?

c#asp.netcachingperformancecounter

提问by Mike Comstock

I'm using the ASP.net cache in a web project, and I'm writing a "status" page for it which shows the items in the cache, and as many statistics about the cache as I can find. Is there any way that I can get the total size (in bytes) of the cached data? The size of each item would be even better. I want to display this on a web page, so I don't think I can use a performance counter.

我在一个 web 项目中使用 ASP.net 缓存,我正在为它编写一个“状态”页面,显示缓存中的项目,以及我能找到的关于缓存的尽可能多的统计信息。有什么方法可以获得缓存数据的总大小(以字节为单位)?每个项目的大小会更好。我想在网页上显示它,所以我认为我不能使用性能计数器。

采纳答案by Ryan Cook

I am looking at my performance monitor and under the ASP.NET Apps v2.0.50727category I have the following cache related counters:

我正在查看我的性能监视器,在ASP.NET Apps v2.0.50727类别下,我有以下缓存相关计数器:

Cache % Machine Memory Limit Used

使用的缓存 % 机器内存限制

Cache % Process Memory Limit Used

使用的缓存 % 进程内存限制

There are also a lot of other cache related metrics under this category.

此类别下还有许多其他与缓存相关的指标。

These should be able to get you the percentage, then if you can get the total allowed with Cache.EffectivePrivateBytesLimitor some other call you should be able to figure it out. I do not have personal experience with these counters so you will have to do some research and testing to verify.

这些应该能够为您提供百分比,然后如果您可以获得允许的总数Cache.EffectivePrivateBytesLimit或其他一些电话,您应该能够弄清楚。我没有这些计数器的个人经验,所以你必须做一些研究和测试来验证。

Here is a quick start article on reading from performance counters: http://quickstart.developerfusion.co.uk/quickstart/howto/doc/PCRead.aspx

这是一篇关于从性能计数器读取的快速入门文章:http: //quickstart.developerfusion.co.uk/quickstart/howto/doc/PCRead.aspx

回答by Igal Serban

Have not tried it. But maybe you can use Cache Manager plug-in for ASP.NET. Or use it as example.

没试过。但也许您可以使用ASP.NET 的缓存管理器插件。或者以它为例。