To change the duration, follow these steps:
How to use dynamic duration value in output caching? (please indicate the original author)
I would inherit from the OutputCache attribute and set Duration :
public static class CacheConfig { public static int Duration = 36600; } public class MyOutputCacheAttribute : OutputCacheAttribute { public MyOutputCacheAttribute() { this.Duration = CacheConfig.Duration; } } [MyOutputCache(VaryByParam = "none")] public ActionResult Index() { return View(); }
Then you can dynamically and globally change the Duration using CacheConfig.Duration
And you can still override the global settings for each action if you want:
[MyOutputCache(Duration = 100, VaryByParam = "none")] public ActionResult OtherAction() { return View(); }
You can then flush the server cache immediately after the duration has changed on its own. Here's how:
"The ASP.NET cache object is located in the System.Web namespace, and since it is a common cache implementation, it can be used in any application that references this namespace.
The System.Web.Caching.Cache class is an object cache. It is accessed through the static property System.Web.HttpRuntime.Cache or through the properties of the instance assistant System.Web.UI.Page and System.Web.HttpContext.Cache. Therefore, it is available outside the context of the request. There is only one instance of this object in the entire application domain, so an HttpRuntime.Cache object can exist in every application domain outside of Aspnet_wp.exe.
The following code shows how to access the ASP.NET cache object from a standard application.
HttpRuntime httpRT = new HttpRuntime(); Cache cache = HttpRuntime.Cache;
After accessing the cache object for the current request, you can use its elements in the usual way. "
REF: Deprecated MSDN Source: Caching Architecture Guide for the .NET Framework
Note. In .Net 3.5 you can only use the InProc cache, in .NET 4 you can store the cache outside the process, as well as using custom CacheProviders .
I want to emphasize this point: if it is assumed that the cache will last longer than AppPool restarts (for example, daily), then you need to cache outside the process.
Also check its caching on the server: http://msdn.microsoft.com/en-us/library/system.web.ui.outputcachelocation.aspx