Search code examples
c#asp.net-mvcoutputcache

How to customize OutputCache key in MVC, c#?


I'm working with MVC 5 and Razor engine.
I have a controller's action as the following:

[HttpPost]
[ValidateAntiForgeryToken]
[OutputCache(Duration = 120, Location = OutputCacheLocation.Server, VaryByParam = "*")]
public PartialViewResult Index(DevicesAjaxViewModel viewModel)
{ ... }

As you can see the action parameter is a class, when ever I'm using OutputCache nothing cached and action runs in each request. I thing it's because of cache key.
So how can I customize OutputCache? Is it possible?


Solution

  • You do not have caching because VaryByParam is set to everything - *. Usually that option is used to specify part of the input parameters (your viewModel) of the controller action.