简体   繁体   English

跨工作进程清除MemoryCache

[英]Clear MemoryCache across worker processes

I have an ASP.NET MVC application that runs on IIS 7. It is setup as a web garden and the number of worker processes matches the number of my processors. 我有一个在IIS 7上运行的ASP.NET MVC应用程序。它设置为网络花园,辅助进程的数量与我的处理器的数量匹配。 I tend to experience some heavy load at times and this setup as worked best. 我有时会遇到一些沉重的负担,这种设置效果最好。

I have implemented some caching using System.Web.Cache. 我已经使用System.Web.Cache实现了一些缓存。 I will occasionally need to invalidate some of items in my cache however I cannot clear the cache across all processes. 有时我需要使缓存中的某些项目无效,但是我无法在所有进程中清除缓存。

Does the .NET 4 System.Runtime.Caching features make this any easier? .NET 4 System.Runtime.Caching功能是否使此操作更容易? Here is a similar question but I hoping there is better advice with .NET 4. Flush HttpRuntime.Cache objects across all worker processes on IIS webserver 这是一个类似的问题,但是我希望对.NET 4有更好的建议。 在IIS Web服务器上的所有辅助进程中刷新HttpRuntime.Cache对象。

System.Web.Cache and System.Runtime.Caching provide almost the same features, it is just a simple memory cache where items in the cache can have an expiration time, dependencies etc... System.Web.Cache和System.Runtime.Caching提供几乎相同的功能,它只是一个简单的内存缓存,其中缓存中的项目可以具有到期时间,依赖项等。

If you want to run your site on multiple physical machines or in your case you run it as web garden, caching data in any in process cache doesn't make a lot of sense because it would cache it for each process again. 如果要在多台物理计算机上运行站点,或者将其作为Web Garden运行,那么在进程内缓存中缓存数据就没有多大意义,因为它将为每个进程再次缓存它。 This will let the memory consumption grow pretty quickly I guess... 我猜这将使内存消耗快速增长。

In those scenarios a distributed cache system is the best choice, because all processes can leverage the already cached data... 在这些情况下,分布式缓存系统是最佳选择,因为所有进程都可以利用已经缓存的数据...

I worked with 2 pretty popular distributed in memory cache systems, one is memcached which was also mentioned in the your link. 我使用了2种非常流行的分布式内存缓存系统,其中一种是memcached ,您的链接中也提到了这一点。

The other one is the app fabric cache , here is a good example of how to use it 另一个是应用程序结构缓存这是如何使用它的一个很好的例子

Memchached is a "simple" cache, it doesn't care about security and all this stuff in the first place. Memchached是一个“简单”的缓存,一开始它并不关心安全性和所有这些东西。 But it is very easy to implement and there are good .Net clients which are really simple to use, almost exactly as the .Net build in crap. 但这很容易实现,并且有很好的.Net客户端 ,它们的使用非常简单,几乎与.Net内置的废话完全相同。

If you want to encrypt the data transfers of your cache and have all this high secured, you might want to go with app fabric... 如果您想对缓存的数据传输进行加密并确保所有这些高安全性,则可能要使用应用程序结构...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM