prevent许多不同的MVC填满ASP.NET缓存网址 [英] Prevent many different MVC URLs from filling ASP.NET Cache

查看:93
本文介绍了prevent许多不同的MVC填满ASP.NET缓存网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的网站使用ASP.NET MVC在它的网页的一部分。这些URL通常的形式 HTTP://oursite/detail.mvc/12345/pictures/ 在这个网址中, 12345是在数据库中的ID。我们已经为我们展示详细页几十万的对象。最近我们注意到,在该网站的内存占用上升,所以我调查了一下。我们做了生产现场的内存转储,发现一个显著量的总内存使用是造成该表格的缓存字符串dmachine /根目录/ 1 /网站/ detail.mvc / 12345 /图片/和H :\网站\ detail.mvc \ 12345 \图片\

Our website uses ASP.NET MVC for a part of the pages in it. These URLs typically have the form http://oursite/detail.mvc/12345/pictures/ In this URL, the 12345 is an ID in the database. We have several hundred thousands objects for which we show detail pages. Recently we noticed a rise in the memory use for the site, so I investigated a bit. We made a memory dump of the production site and found that a significant amount of the total memory use was cause by strings in Cache of the form "dmachine/webroot/1/site/detail.mvc/12345/pictures/" and "H:\site\detail.mvc\12345\pictures\".

进一步调查和大量使用反射器的已表明,这些字符串存储在ASP.NET缓存在一个System.Web.CachedPathData对象的形式。这是通过ConfigurationManager中时,它读取web.config文件中的信息创建的。它调用HttpContext.GetSection() - > HttpContext.GetConfigurationPathData() - > CachedPathData.GetVirtualPathData()。最终,在CachedPathData.GetConfigPathData,虚拟路径被确定为所请求的路径,这是缓存在ASP.NET缓存没有过期。

Further investigation and heavy use of Reflector has showed that these strings are stored in the ASP.NET Cache in the form of a System.Web.CachedPathData object. This is created by ConfigurationManager when it reads information from the web.config file. It calls HttpContext.GetSection() --> HttpContext.GetConfigurationPathData() --> CachedPathData.GetVirtualPathData(). Eventually, in CachedPathData.GetConfigPathData, the virtual path is determined for the requested path and this is cached in the ASP.NET Cache without expiration.

现在的问题是,我们有几百万不同的网址,并为每个路径配置系统存储了许多字符串(configPath来,虚拟路径,物理路径)的缓存。随着时间的推移,该信息消耗数百MB的,所有的allmost在缓存中的数据的。

Now the trouble is that we have millions of different URLs, and for each path the Configuration system stores a number of strings (configPath, virtual path, physical path) in cache. Over time, this information consumes several hundreds of MB, allmost all of the data in cache.

我认为当内存变得稀缺,这些作品将被删除,但在操作,他们不相信成长过程和成长。它也似乎非常低效。有没有办法告诉HttpContext的不缓存此信息为每个唯一的网址是什么?或许我们可以映射请求路径,以一个简单的URL第一,有一个用于选择正确的web.config?

I assume that when memory gets scarce, these entries will be removed, but in operations they don't trust processes that grow and grow. It also seems very inefficient. Is there a way to tell the HttpContext not to cache this information for each unique URL? Or maybe we can map the request path to a simpler URL first and have that used to select the correct web.config?

推荐答案

嗯,我考虑了一下(师德和我在同一家公司工作),我们有两种选择,据我可以告诉:

Well I thought it over (Teun and I work at the same company), and we have two options as far as I can tell:

  1. 什么也不做。本文包含从一个asp.net团队球员注释,它显示了几个方法来prevent从不断扩张的高速缓存:的 http://forums.asp.net/p/985551/3297967.aspx#3297967 ,但并不能解决写了一个缓存条目的问题每一个可能的路径,但保证缓存将不会抛出一些内存溢出异常。

  1. Do nothing. This article contains a comment from one asp.net team guy, and it shows a couple of ways to prevent the cache from growing and growing: http://forums.asp.net/p/985551/3297967.aspx#3297967, yet doesn't solve the problem of writing a cache entry for each possible route but guarantees that the cache won't throw some out of memory exception.

有一种变通方法解决此问题,使用查询字符串参数,而不是固定的路线(/controller.mvc?action=X&params=Y而不是controller.mvc /动作/ PARAMS)。这种方式只controller.mvc被缓存。

Solve the problem with a workaround, use querystring parameters instead of fixed routes (/controller.mvc?action=X&params=Y instead of controller.mvc/action/params). This way only controller.mvc gets cached.

毕竟,我不认为这真的是个问题。

After all, I don't think this really is a problem.

这篇关于prevent许多不同的MVC填满ASP.NET缓存网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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