Friday, November 10, 2017

Caching partials in Umbraco 7.7

Umbraco has a nice way of implementing output caching in the views. It is exactly the same ass calling a partial, but you can say how long you want that partial to be cached and how should Umbraco understand if it should return cached data or build it again.
You could find the documentation in here.

Quick examples:

one can use CachedPartial without specifying anything else which means that you want the same partial showing every time no matter where it is.
For instance if you want to show footer or menu of your site, it is pretty easy to have them in a partial and then just call Html.CachedPartial("_menu",....) on the master page/ layout page.

  @Html.CachedPartial("_partial", Model, chachtime)//caching for everypage
On the other hand you might want to show different views for each member. An example could be a module to show username or other user specified data.
  @Html.CachedPartial("_partial", Model, chachtime,cacheByMember:true)//caching based on the member
Then there are times that you want to have your data showing differently based on different pages that they are on. For instance you want to write meta data of each page, but you don't care which user is that.
  @Html.CachedPartial("_partial", Model, chachtime,cacheByPage:true)//caching based on pages
 We can also do combination of page and members. 
  @Html.CachedPartial("_partial", Model, chachtime,cacheByPage:true,cacheByMember:true)//caching based on pages and members

But what if you want to cache your partial based on something else? What if you have some querystrings that contains some items that you want to differentiate based on that?
Lets say you have a small advertising site and for some reasons, you have your product Ids in the querystring. If you cache the page by page, it will just show everyone the first product that someone has browsed for the cache period which is not good.
Cachebymemebr is not also usable because you don't care if the person is logged in or different. You just care about the querystring that you have (productIds)
The way to do it is using contextualKeyBuilder like below: 

@Html.CachedPartial("_partial", Model, chachtime, 
contextualKeyBuilder:(o, dictionary) => 
CurrentPage.Id.ToString() + Request.QueryString.ToString())
You can specify the key based on your scenario or even pageview data.


  1. Thanks for this blog. I have found some interesting blogs on google. You can check these blogs also which are related to technologies…..
    Avast Login
    avg login
    bullguard login

  2. Wow very nice post from you. I like this and its really sharable content and great as well as. Get know of me . Office Login Must go on this link for the support help regarding the Microsoft office.

  3. cheap moncler jackets, combining elegant style and cutting-edge technology, a variety of styles of cheap moncler shoes, the pointer walks between your exclusive taste style.

  4. bullguard login- PC security is the way toward anticipating and distinguishing unapproved utilization of your PC. Counteractive action estimates enable you to prevent unapproved clients from getting to any piece of your PC framework. Recognition causes you to decide if somebody endeavored to break into your framework, in the event that they were effective, and what they may have done. | is-install-mdl-install | bullguard login | bullguard Internet security | bullguard download

  5. McAfee service offers trusted safety to protect data and devices. So, you can shop, surf & keep all your devices safe online with the convenience of a single subscription. ULTIMATE antivirus, identity, and privacy security for all of your computers/Personal computers or notebooks (Windows, Macs), smartphones, and tablets. We help to activate McAfee retail card. | | total protection