Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use OutputCache on mvc JsonResult controller methods?

I am trying to do this, and it leads to result with contentlen 0

It looks like:

[OutputCache(Duration = 36000)]
public JsonResult GetFileClasses() 
{
   return this.Json(TopicConfig.FileExtensionsSettings.List)
}

Any ideas?

like image 926
st78 Avatar asked Jan 15 '10 20:01

st78


People also ask

What is the use of OutputCache attribute in MVC?

The output cache enables you to cache the content returned by a controller action. That way, the same content does not need to be generated each and every time the same controller action is invoked. Imagine, for example, that your ASP.NET MVC application displays a list of database records in a view named Index.

What is OutputCache in action filter?

In ASP.NET MVC, there is an OutputCache filter attribute that you can apply and this is the same concept as output caching in web forms. The output cache enables you to cache the content returned by a controller action. Output caching basically allows you to store the output of a particular controller in the memory.

Where is output cache stored?

The output cache is located on the Web server where the request was processed. This value corresponds to the Server enumeration value. The output cache can be stored only at the origin server or at the requesting client. Proxy servers are not allowed to cache the response.

Which namespace enables the caching parameters in ASP.NET MVC?

NET Framework, caching was available only in the System. Web namespace and therefore required a dependency on ASP.NET classes.


1 Answers

In OutputCacheAttribute you must also specify , VaryByParam parameter. Otherwise you'll get this exception on result processing System.Web.HttpException: The directive or the configuration settings profile must specify the 'varyByParam' attribute. You can try to add this parameter and see if it works.

like image 171
Branislav Abadjimarinov Avatar answered Oct 11 '22 19:10

Branislav Abadjimarinov