如何得知缓存当前消耗了多少内存?
我想根据可用内存量修改滑动过期时间跨度的值。如果站点的流量在任何时间点都很高,则与安静时期相比,更多的数据将添加到缓存中。在这些安静时期,我可以增加滑动过期时间跨度,从而允许数据存储更长时间。但当网站繁忙时,我需要释放内存,这样我对较短的时间跨度感到更满意。
所以我想我的问题如下:
我是否可以找出我添加到HttpRuntime.Cache
中的项目消耗了多少内存?如果是这样,怎么办?
这听起来像是对我所描述的问题的现实解决方案吗?
I'd like to modify the value of my Sliding Expiration time span based on how much memory is available. If the site's traffic is high at any point in time, more data will be added to the cache than during quieter periods. During those quiet periods I can increase the sliding expiration time span, thus allowing data to be stored longer. But when the site is busy I need to free up memory so I'm happier with a shorter time span.
So I guess my questions are as follows:
Is it possible for me to find out how much memory is being consumed by the items I've added to HttpRuntime.Cache
? If so, how?
Does this sound like a realistic solution to the problem I've described?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不太可能想出一个好的算法来以这种方式“帮助”缓存。
只需适当使用优先级参数并让缓存完成其工作即可。
It's unlikely you can come up with a good algorithm for 'helping' the Cache this way.
Just make appropriate use of the priority parameter and let the Cache do its job.