Extending from OutputCache attribute asp.net mvc
Lately, i have been exploring the source code of O开发者_Go百科utputCache attribute in asp.net mvc-3 with intention to inherit and customize it according to needs of my application. I was expecting that it would include some caching mechanism but i failed to locate the place where it stores result of and actionresult in the cache and retrieves on subsequent requests. Moreover, in implementation of onActionExecuting
, onResultExecuting
etc. i have seen code like
if(filterContext.ChildRequest or perhaps ChildAction)
{
}
and if current request is not a child action cache attribute seems to be doing nothing. Can someone explain this behavior. Furthermore, where caching is actually performed if not in OutuptCache attribute?
Based on the code if it is not a child action it delegates the cache handling back to the standard ASP.NET infrastructure. It happens in the OnResultExecuting, where it checks if it is NOT a child action, and then creates an OutputCachedPage wrapper to execute the request. This wrapper inherits from the System.Web.UI.Page and it initializes the output caching with the InitOutputCache method. This method configures the cache policy for the response (Response.Cache). I think the actual caching happens in the System.Web.Caching.OutputCacheModule (OnEnter, OnExit methods) finally, based on the cache policy previously set on the page.
The caching is not performed on the framework level but in the webserver (IIS), intermediate proxies, the final client (browser) cache etc.
The cache location enumeration gives more info on where the data is cached.
精彩评论