Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Cache to maximum level in ASP.NET MVC 4

I have a site that serves mostly static data from a database, so I'd like to have the maximum caching possible. The database is very weak and slow.

I am using shared hosting, so am limited to the [OutputCache] on the Controller and web.config

Is there a "max" strategy?

Ian

like image 247
Ian Vink Avatar asked Sep 07 '13 20:09

Ian Vink


People also ask

How cache is implemented in ASP.NET MVC?

In this, you learn how to cache the output returned from a controller action so that a new user doesn't need to create the same content every time the action is called. Using the OutputCache attribute, you can enable output caching functionality by applying an individual controller action or an entire controller class.

What is the default cache duration value in ASP.NET MVC?

By default, this attribute filter cache the data till 60 seconds.

What are the different caching techniques available in .NET MVC?

Any (Default)- Content is cached in three locations- the Web Server, any proxy Servers and the Web Browser. Client- Content is cached on the Web Browser. Server- Content is cached on the Web Server. ServerAndClient- Content is cached on the Web Server and the Web Browser.

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.


1 Answers

You can try going for the below option, it should give you 2147483647 seconds (24855 days) max duration for int32:

[OutputCache(Duration = int.MaxValue)]

Please note however that it is not guaranteed that your cache will be preserved exactly for the amount of time that you specify; it depends on memory utilization - if memory becomes too low, cache will be removing data automatically.

like image 158
AntonM Avatar answered Nov 06 '22 05:11

AntonM