Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mike 90 posts 258 karma points
    Mar 10, 2015 @ 02:42
    mike
    0

    How does partial view caching work?

    I recoded my menu partial view to work recursively for nested items so there was a lot more calls.  I enabled show trace to have a look at performance and noticed that it only loads once.  After that it seems to load cached version of the page until a change is made.

    I'm working locally but tried in a different browser and it still didnt take long to load unless I made a change to menu so I think it's not saved to my session.

    Obviously I don't want all these calls made on every page load.  It can load from cache every time and just re-build when an item is published.

    I imagined I would have to manually add it to the cache or something but it seems like something automatic is happening.

    Is there any explanation on how caching works in MVC partial views?  I have read the documentation I could find and blogs but it only shows how to create an extension method to add a partial view to the cache and specify a time period.

    I was guessing a good idea would be to cache it for like 24 hours and then create function to rebuild it on an after publish event.  I don't want to do that work if the same thing is happening automatically.

    Can anyone explain to me how umbraco cache works?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 10, 2015 @ 10:20
    Dave Woestenborghs
    0

    Hi Mike,

    Can you post some code. Maybe that helps to pinpoint your problem.

    Dave

  • John Churchley 272 posts 1258 karma points c-trib
    Mar 10, 2015 @ 14:54
  • mike 90 posts 258 karma points
    Mar 10, 2015 @ 20:30
    mike
    0

    Hi Dave,

    I want to know how umbraco handles caching when I don't have any caching code.  It looks like it is doing something but I can't find any explanation or write up (although on a few blogs it was referred to in general terms).

    Hi John,

    Thanks for the link.  I am more interested in caching a dynamic page for performance reasons.  Lets say a controller/view has lots of queries to the published cache.  For instance iterating over many nodes, checking for certain values and applying some additional logic or sorting.  This page is using processer time to generate.  For instance my menu partial takes 700ms to render the first time its loaded. Subsequent views it takes just 20ms to render.  It looks like umbraco or .net has created a cache for it automatically.  When I publish a new page it will render once again the first time at 700ms.  I don't know how long it stays like that.  I am not sure if it is umbraco or just a behind the scenes thing where the variables are still loaded in memory and it will just stay quick until garbage collection removes them.

    If the data doesnt change often then I feel like I should be caching this page and just re-building the cache when the data changes or I will be stressing my server unduly.

    I have been doing some googling and read an article on dependency caching in entity framework.  The explanation given was that you could add an item to the cache and it would stay in cache until a specified SQL table changed (although details on how to do this were light).  This seems like an ideal process and from looking at how umbraco works I was wondering if something like this happens automatically?  Can the settings for this be played with?

    I just found out about the hybrid framework so I am going through that now to see what I can learn.  It seems that people generally create a cache manager that they then bind to certain events to add/remove items so I guess this is where I must also start.

Please Sign in or register to post replies

Write your reply to:

Draft