To change the duration follow this:
How to use dynamic duration value in Output Caching? (please credit original author)
I would inherit from the OutputCache
attribute and set the 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 change the Duration
dynamically and globally through the CacheConfig.Duration
And you can still override the global setting on every action if you want:
[MyOutputCache(Duration = 100, VaryByParam = "none")]
public ActionResult OtherAction()
{
return View();
}
Then you can reset the server cache immediately when Duration has changed yourself. Here's how:
"The ASP.NET cache object is located in the System.Web namespace, and because it is a generic cache implementation, it can be used in any application that references this namespace.
The System.Web.Caching.Cache class is a cache of objects. It is accessed either through the static property System.Web.HttpRuntime.Cache or through the helper instance properties System.Web.UI.Page and System.Web.HttpContext.Cache. It is therefore available outside the context of a request. There is only one instance of this object throughout an entire application domain, so the HttpRuntime.Cache object can exist in each application domain outside of Aspnet_wp.exe.
The following code shows how you can access the ASP.NET cache object from a generic application.
HttpRuntime httpRT = new HttpRuntime();
Cache cache = HttpRuntime.Cache;
After you access the cache object for the current request, you can use its members in the usual way."
REF: Obsolete MSDN Source: Caching Architecture Guide for .NET Framework Applications
Note: With .Net 3.5 you could only use InProc cache, with .NET 4 you can store your cache outside the process as well as using custom CacheProviders.
I want to emphasize this point, if the cache is supposed to last longer than the AppPool recycles (eg daily) then you need to cache Out-Of-Process.
Also check its being cached on the server:
http://msdn.microsoft.com/en-us/library/system.web.ui.outputcachelocation.aspx
reset Server catch? (in ASP.Net MVC by C#)
, the(in ASP.Net MVC by C#)
was deleted? – Entitle(in ASP.Net MVC by C#)
why removed? – Entitle(in ASP.Net MVC by C#)
is better specified in tags (indexed by search engines) than free-text in a title. – Administrate