asp.net caching limit?(asp.net 缓存限制?)
问题描述
可能重复:
ASP.NET 缓存最大大小
我正在使用 asp.net 缓存(流式代码)缓存大量数据表:
I'm caching quite a lot of datatables using asp.net caching (the floowing code):
HttpContext.Current.Cache.Insert(GlobalVars.Current.applicationID + "_" + cacheName, itemToCache, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(240));
但是我认为服务器上的缓存已满,不得不从数据库中重新获取数据表数据.可以在服务器上缓存的数据量或可以调整的任何 IIS 设置是否有任何限制?
However I think that the cache on the server is getting full and having to re-obtain the datatable data from the database. Is there any limit to the amount of data that can be cached on the server or any IIS settings that can be tweaked?
推荐答案
有办法升级限制,但我强烈建议你使用其他类型的缓存系统(更多关于这个).
There is a way to upgrade the limit but I would strongly recommend that you use other kind of Caching System (more about this below).
要了解有关 .NET 缓存限制的更多信息,请阅读 这个很好的答案来自 Microsoft .NET 团队成员.
To know more about the .NET Caching limitation, please read this great answer from a Microsoft .NET Team member.
如果你想查看当前.NET Cache的限制,可以试试:
If you want to see the current limits of .NET Cache, you can try:
var r = new Dictionary<string, string>();
using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache % Machine Memory Limit Used", true))
{
pc.InstanceName = "__Total__";
r.Add("Total_MachineMemoryUsed", String.Concat(pc.NextValue().ToString("N1"), "%"));
}
using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache % Process Memory Limit Used", true))
{
pc.InstanceName = "__Total__";
r.Add("Total_ProcessMemoryUsed", String.Concat(pc.NextValue().ToString("N1"), "%"));
}
using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache API Entries", true))
{
pc.InstanceName = "__Total__";
r.Add("Total_Entries", pc.NextValue().ToString("N0"));
}
using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache API Misses", true))
{
pc.InstanceName = "__Total__";
r.Add("Total_Misses", pc.NextValue().ToString("N0"));
}
using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache API Hit Ratio", true))
{
pc.InstanceName = "__Total__";
r.Add("Total_HitRatio", String.Concat(pc.NextValue().ToString("N1"), "%"));
}
using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache API Trims", true))
{
pc.InstanceName = "__Total__";
r.Add("Total_Trims", pc.NextValue().ToString());
}
内存缓存
我目前正在使用 Memcached,如果您将网站托管在某个地方,则可以使用以下付费服务:
MemCached
I'm currently using Memcached, and if you're hosting your site somewhere, you can use a paid service like:
- http://www.memcachier.com/
或者,如果您使用自己的服务器,您可以下载 Couchbase 社区版 并托管我们自己的.
Or, if you're using your own server, you can download Couchbase Community Edition and hosted our own.
你会在这里找到更多关于 MemCache 使用的问题,例如:
You will find more questions here about the use of MemCache, such as:
- 您使用哪个 .NET Memcached 客户端,EnyimMemcached 与 BeITMemcached 对比?
- 如何开始使用 memcached
要在不改变代码的情况下使用其他缓存系统,你可以采用创建一个接口,比如
To use other cache system without changing your code, you could adopt to create an interface, like
public interface ICacheService
{
T Get<T>(string cacheID, Func<T> getItemCallback) where T : class;
void Clear();
}
那么您是否正在使用 .NET 缓存,您的实现将类似于
then is you're using .NET Cache, your implementation would be something like
public class InMemoryCache : ICacheService
{
private int minutes = 15;
public T Get<T>(string cacheID, Func<T> getItemCallback) where T : class
{
T item = HttpRuntime.Cache.Get(cacheID) as T;
if (item == null)
{
item = getItemCallback();
HttpRuntime.Cache.Insert(
cacheID,
item,
null,
DateTime.Now.AddMinutes(minutes),
System.Web.Caching.Cache.NoSlidingExpiration);
}
return item;
}
public void Clear()
{
IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator();
while (enumerator.MoveNext())
HttpRuntime.Cache.Remove(enumerator.Key.ToString());
}
}
你会使用它:
string cacheId = string.Concat("myinfo-", customer_id);
MyInfo model = cacheProvider.Get<MyInfo>(cacheId, () =>
{
MyInfo info = db.GetMyStuff(customer_id);
return info;
});
如果您使用的是 Memcached,您只需创建一个实现 ICacheService
的新类,然后使用 IoC 或直接调用来选择所需的类:
if you're using Memcached, all you need to do is create a new class that implement ICacheService
and select the class you want, either by using IoC or direct call as:
private ICacheService cacheProvider;
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
if (cacheProvider == null) cacheProvider = new InMemoryCache();
base.Initialize(requestContext);
}
这篇关于asp.net 缓存限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:asp.net 缓存限制?
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01