2012-05-03 10 views

Respuesta

10

Me heredar del atributo OutputCache y poner allí el 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(); 
} 

A continuación, puede cambiar el Duration forma dinámica y globalmente A través del CacheConfig.Duration

y todavía se puede anular la configuración global sobre todas las acción si lo desea:

[MyOutputCache(Duration = 100, VaryByParam = "none")] 
public ActionResult OtherAction() 
{ 
    return View(); 
} 
Cuestiones relacionadas