OutputCache and RenderAction cache whole page

Error processing SSI file

Answers

  1. Jaxxon

    • 2018/1/4

    I blogged a solution to this problem here. It's simple, but it only works if you're using the WebFormViewEngine. We will look hard into figuring out what it will take to make this work for all view engines.

  2. Kylen

    • 2020/4/4

    I blogged a solution to this problem here. It's simple, but it only works if you're using the WebFormViewEngine. We will look hard into 

  3. Evan

    • 2019/5/11

    I have a ViewPage that contains <% Html.RenderAction<MyController>(c => c.SidebarStats()); %>. On the controller action for the action SidebarStats I have an OutputCache action filter to cache only that part of the page. However, the whole page is getting cached and not just that action.

  4. Tristian

    • 2020/10/18

    I blogged a solution to this problem here. It's simple, but it only works if you're using the WebFormViewEngine. We will look hard into figuring out what it 

  5. Owen

    • 2019/6/21

    I'm now using what Steve Sanderson made in his blog and it's very nice:

    public class ActionOutputCacheAttribute : ActionFilterAttribute
    {
        // This hack is optional; I'll explain it later in the blog post
        private static readonly MethodInfo _switchWriterMethod = typeof (HttpResponse).GetMethod("SwitchWriter",
                                                                                                 BindingFlags.Instance |
                                                                                                 BindingFlags.NonPublic);
    
        private readonly int _cacheDuration;
        private string _cacheKey;
        private TextWriter _originalWriter;
    
        public ActionOutputCacheAttribute(int cacheDuration)
        {
            _cacheDuration = cacheDuration;
        }
    
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            _cacheKey = ComputeCacheKey(filterContext);
            var cachedOutput = (string) filterContext.HttpContext.Cache[_cacheKey];
            if (cachedOutput != null)
                filterContext.Result = new ContentResult {Content = cachedOutput};
            else
                _originalWriter =
                    (TextWriter)
                    _switchWriterMethod.Invoke(HttpContext.Current.Response,
                                               new object[] {new HtmlTextWriter(new StringWriter())});
        }
    
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if (_originalWriter != null) // Must complete the caching
            {
                var cacheWriter =
                    (HtmlTextWriter)
                    _switchWriterMethod.Invoke(HttpContext.Current.Response, new object[] {_originalWriter});
                string textWritten = (cacheWriter.InnerWriter).ToString();
                filterContext.HttpContext.Response.Write(textWritten);
    
                filterContext.HttpContext.Cache.Add(_cacheKey, textWritten, null,
                                                    DateTime.Now.AddSeconds(_cacheDuration), Cache.NoSlidingExpiration,
                                                    CacheItemPriority.Normal, null);
            }
        }
    
        private string ComputeCacheKey(ActionExecutingContext filterContext)
        {
            var keyBuilder = new StringBuilder();
            foreach (var pair in filterContext.RouteData.Values)
                keyBuilder.AppendFormat("rd{0}_{1}_", pair.Key.GetHashCode(), pair.Value.GetHashCode());
            foreach (var pair in filterContext.ActionParameters)
                keyBuilder.AppendFormat("ap{0}_{1}_", pair.Key.GetHashCode(), pair.Value.GetHashCode());
            return keyBuilder.ToString();
        }
    }
    

    Please visit Steve Sanderson blog's article for more information.

  6. Kelly

    • 2019/4/3

    if you use $.load to get html into a div, then if the webserver set the caching headers, it will be cached. if you make a $.ajax call for json data, and the webserver says cache it, it will be cached. if your page navigates, then the browser needs to download the whole page, unless the whole page is cached. if you use ajax to update a div via a partial view result, then the layout is not included.

  7. Shawn

    • 2020/10/29

    The problem is I want to cache the Menu data since it's consistent on all pages. Yet when I add the OutputCache parameter to my Action it 

  8. Jase

    • 2018/2/4

    I define OutputCache attributes on top of my controller actions, so that the server can give the same response quickly to different users. Bu it caches the whole page. I mean the master page is also cached if I have cached an action that returns a View(). So the user account information on top of the master page gets shared by every user.

  9. Isaac

    • 2016/10/16

    According to Microsoft this is a known bug with no known fix. Only workarounds suggested are to create your own OutputCache action filter.

  10. Casen

    • 2021/10/16

    Up until this time we were only able to output cache the entire view in ASP. the Html.Action and Html.RenderAction helpers used within the view in ASP.

  11. Chavez

    • 2019/3/27

    The OutputCache attribute is commonly given as an example of a result filter in ASP.NET MVC. This MSDN page is one place. OutputCache and RenderAction cache whole

  12. Russo

    • 2015/10/15

    Donut hole caching is where you cache one or more parts of a page, but not the entire page. It is handled by using the built-in OutputCache attribute on one or 

  13. Alden

    • 2018/10/17

    In ASP.NET MVC, we can cache whole action with OutputCache Attribute. In mean while if we do not want to cache the entire action, we just want to cache the small portion of page/view. Then this can be achieved by using combination of ChildActionExtensions and OutputCache Attribute.

  14. Case

    • 2016/6/8

    To cache a partial view output, we again use the same OutputCache View Cache</h2> @{ Html.RenderAction("PartialViewCacheChild"); } <h2>This date and 

  15. Zander

    • 2018/1/1

    Donut hole caching is where you cache one or more parts of a page, but not the entire page. It is handled by using the built-in OutputCache attribute on one or more child actions (called using Html.Action or Html.RenderAction from the parent view). It has been available since ASP.NET MVC 3.

  16. Dorian

    • 2017/8/14

    RenderPartial method ignores any OutputCache directives on the view user control. If you happen to use Html.RenderAction from MVC Futures which 

  17. August

    • 2015/7/27

    You enable output caching by adding an [OutputCache] attribute to either an individual controller action or an entire controller class. For example, the controller in Listing 1 exposes an action named Index (). The output of the Index () action is cached for 10 seconds. Listing 1 – Controllers\HomeController.cs.

  18. Dominic

    • 2021/8/4

    NET MVC application by taking advantage of the output cache. to either an individual controller action or an entire controller class.

  19. Grassi

    • 2016/5/19

    I'm using Html.RenderAction in a masterpage ( to render page header with links with OutputCache, returns partial control and gets cached as expected.

  20. Rivera

    • 2020/11/13

    Here in controller level caching, it's cached all the action content under the control. [OutputCache(Duration = 10, VaryByParam = “none” , Location = 

Comments are closed.

More Posts