So again we are feeling good, we only need to change the output cache duration in one place, so any time we need to change the expiration time it can easily be done.

But wait a minute, on one of our controllers, we are returning a partials view with a RenderAction in the view, but we get the following error. 

OutputCacheAttribute for child actions only supports Duration, VaryByCustom, and VaryByParam values. Please do not set CacheProfile, Location, NoStore, SqlDependency, VaryByContentEncoding, or VaryByHeader values for child actions.

Output Cache In MVC

So when using CacheProfile, don't try and use it with a RenderAction as you will receive the error above, instead, you will need to fall back using [OutputCache(Duration = 10, VaryByParam = "id")] on your controller action.

You can download the full code example from GitHub

There is so much more to caching, but I hope you found this brief blog helpful, if so, please leave a comment below.

Leave a comment

*
*

New IT Directory

IntuWebdesign is looking to create a comprehensive worldwide IT directory, if you are interested in been listed in the directory, please complete the form and once the directory goes live, we will send you an email on how to sign up.