In this tutorial, you will learn how to enable caching within your Episerver CMS-powered website. Adding caching capabilities to your site is important to ensure your webpages are quickly anfd you are not messing up your web vital ranking. If you are looking at improving your Episerver CMS page speeds, this is the tutorial for you 🔥🔥🔥

Output Cache: The most common form of caching within an ASP.NET Framework based website, is the output cache. To enable output caching to your website, you need to do two things.. First, within web.config you need to make sure outputCacheSettings is set to true. Second, you will need to add the [OutputCacheAttribute] onto the controllers that you want to cache. Simply decorate a controller like this:

If you have a lot of controllers within your solution, adding cache attributes throughout your might seem like a hassle. If you want to just enable the cache for all pages globally, you can add this code within global.asax:

If after enabling the global cache, you notice one of your controllers is not working as expected, fear not 😱. You can explicitly configure a controller to be excluded from the cache. You can do this using the [OutputCacheAttribute] by setting the controller to use a cache period of 0, like this:

When following this approach, there are a few gotchas 😕. Below covers three handy tips that I wished I knew about before starting:

  • VaryByParam: Several articles I found inferred that you can use id;epilanguage for the VaryByParam. On testing, I encountered issues so I recommend you use *
  • If you set VaryByParam="None" the menu in the editor will break
  • If you remove the outputCacheSettings element from the web.config the editor will not load

Caching VPP Folder contents: When using Episerver 6, you will likely want to cache the VPP folder. By default the cache expiration time on VPP items is set to -1 day. This value can be changed by updating the following tag in your web.configconfigurationsection:

Adding Kernal Caching: You can also enable additional static file caching using kernal caching. You can enable Kernal caching within web.config within the system.webserver section:

Enabling Client-Side Caching: To enable the cache headers for all static content within web.config add this:

With these tweaks, your Epsierver CMS-powered website should run at a blazing pace 🏁💨🏁. Happy Coding 🤘