ASP.NET MVC hits outputcache for every action

We are running quite a large site build with ASP.NET MVC 3 and AppFabric as a distributed caching solution. We have implemented a custom OutputCacheAdapter to use our AppFabric cluster.

We are seeing that ASP.NET calls the OutputCacheProvider.Get() method for every action, even if that action is NOT decorated with a @OutputCacheAttribute.

That isn't much of a problem if you use the default outputcacheprovider but it is when you are running an outputcacheprovider that resides on seperate machines.


It is by design that the the output cache is checked first for a cached copy of the page. If there is a cached copy, it's returned and nothing further is executed. In particular, no controller and no controller action is derived, inspected or executed. This happens only if the page is not cached.

You will need to change your cache provider so that it can quickly determine if a page can potentially be cached. Only if it is a cachable page, then it should go and check the distributed cache. This check cannot based on the OutputCacheAttribute as they are not available during this part of the request processing. Instead, the quick check must be made with the URL, the cookies and other HTML header information.


You can use Donut Cache outputcache attribute which lets you to define a prefix for output cache keys. So in your custom provider just get/set the cache if cache key starts with your own prefix.

链接地址: http://www.djcxy.com/p/58838.html

上一篇: 使用自定义名称创建工作簿而不将其保存到磁盘

下一篇: ASP.NET MVC为每个动作都输出outputcache