In this tutorial, you will learn all about the CachePartial() helper and how you can use it to level up your Umbraco webpages performance. When building any website performance matters. Anything you can do to tweak and hone your users experience the better. When using partial views within Umbraco you can definitely leverage the CachedPartial() helper. The CachedPartial() helper can be thought of like a decorator. You pass in a reference to a normal partial view and the helper will cache it for you. The method declaration for the helper looks like this:

Where <Name Of View> is the name of the partial view that you want to wrap, <View Model> is the model and <Cache Duration> is the time in seconds the helper will cache the partial for.

One quirk to be aware of is that the helper will work globally. Meaning even if you pass different parameters for the same partal on different pages then view you may encounter unexpected results. Imagine you had two pages:

Page One

Page Two

In the example above the first instance of MyPartial will be cached and the second instance will be ignored. If you need page-specific caching you can use the cache-by-page override, like this:

Using the overload means you can differentiate between different caches.

TIP Caching WILL only happens if you are NOT in debug mode.

Another thing to note is this override only works on different pages. If you wanted to use the same part with different data on the same page then you will need to write a custom version of the helper. You can do this like this:

This custom helper can then be used like the: