Using Output Caching helps to improve the performance of an ASP.NET MVC Application. It caches the content returned by an action method so that the same content does not need to be generated each time the same action method is invoked in the controller.
If a page takes a lot of server-side resources to create, such as database calls, file reads, search index hits, etc., it will be a good candidate to use output caching.
EPiServer has an out-of-the-box output cache attribute, but it has some limitations, for instance, it will only work for users who are not logged in, it cannot be used on child actions, and the cached will be invalidated as soon as an editor change the content. For that reason, I decided to create my own content output cache attribute. The idea is to make coding easier.
Some possible scenarios that are supported:
- Child Action Caching.
- Cache only for anonymous users.
- Vary by users, params, and cookies.
- Cache under defined circumstances.
- Core methods can be overridden in inherited classes.
Go to the Package Manager Console and type:
Build the solution and verify that the component was added correctly in the CMS.
The Content Output Cache module allows you to enable, disable, and clear the output cache.
Make sure to set the property httpCacheExpiration in the web.config file, otherwise, the output cache module will not work. Take a look at the image below:
In the next section, you will learn how to work with the output cache library. Go there.