What caching mechanism does OutputCacheAttribute use and how can i extend it?
            Asked
            
        
        
            Active
            
        
            Viewed 391 times
        
    1 Answers
0
            
            
        It uses ASP.NET WebForm caching, and you can extend it by overriding OnResultExecuting.
Refer to:
Code extract from above link.
public override void OnResultExecuting(ResultExecutingContext filterContext) {
    if (filterContext == null) {
      throw new ArgumentNullException("filterContext");
    }
    if (!filterContext.IsChildAction) {
        // we need to call ProcessRequest() since there's no other way to set the Page.Response intrinsic
        using (OutputCachedPage page = new OutputCachedPage(_cacheSettings)) {
            page.ProcessRequest(HttpContext.Current);
        }
    }
}
private sealed class OutputCachedPage : Page {
    private OutputCacheParameters _cacheSettings;
    public OutputCachedPage(OutputCacheParameters cacheSettings) {
        // Tracing requires Page IDs to be unique.
        ID = Guid.NewGuid().ToString();
        _cacheSettings = cacheSettings;
    }
    protected override void FrameworkInitialize() {
        // when you put the <%@ OutputCache %> directive on a page, the generated code calls InitOutputCache() from here
        base.FrameworkInitialize();
        InitOutputCache(_cacheSettings);
    }
}
 
    
    
        Justin Shield
        
- 2,390
- 16
- 12
