Caching is a great way to improve performance for minimal effort. Almost every programming language or framework has a concept of caching as do webservers and things like cloudflare and all kinds of other tools.
Today I'll be talking about caching in Umbraco (keep an eye out for our articles about caching on other platforms). Well not just caching in Umbraco, as it's based on .NET we can use .NET's caching mechanisms to improve the performance of our Umbraco site.
.NET MVC has a handy way to easily cache the output of controller actions using the output cache attribute e.g.: [OutputCache(Duration=10, VaryByParam="none")]
I'm not going to go into huge detail here about how to set up output caching as it's described in detail by microsoft
Output caching is great if your requirements are fairly simple but as your Umbraco application becomes more complex it can quickly become frustrating, hopefully this will save you some hours of googling. Here's why:
1) There's a webconfig setting to enable and disable the output cache which you may think would be great to disable it on your test environments...nope, it doesn't work!!
2) Cache profiles can be used to configure output cache settings without changing code...unless you are trying to cache child actions (which is very handy for improving performance where only part of the page is dynamic). You can't have cache profiles on child actions.
3) Want to remove something from the cache: HttpResponse.RemoveOutputCacheItem, again nope for child actions.
4) If you do want to clear the cache on child actions you need to use a cannon to clear cache the size of a mosquito:
OutputCacheAttribute.ChildActionCache = new MemoryCache(Guid.NewGuid().ToString());
This will destroy your whole cache so has very bad performance implications!
So you've heard me complain a lot so far but whats the answer?
As usual it's donuts! Donut caching is a very clever nuget package which uses MVC filters to store the output of your actions in memory so they can be served super quick!
It also allows you to do all the things above you'd like to with the output cache but cant!
Drop us a line if you need any further info, advice or support from our expert Umbraco certified developers
See how we can improve your online presence.