代码之家  ›  专栏  ›  技术社区  ›  Christian Nielsen

如何重写basecontroller中的OutputCache?

  •  1
  • Christian Nielsen  · 技术社区  · 15 年前

    [输出缓存(NoStore=true,Duration=0,VaryByParam=“none”)]

    2 回复  |  直到 15 年前
        1
  •  1
  •   Christian Nielsen    15 年前

    当nostore头不使用outputcache属性时,通过处理找到了解决方法

    HttpContext.Current.Response.Cache.SetNoStore();

    做这个工作。。

        2
  •  1
  •   user1023602 user1023602    10 年前

    显然,您可以在派生类中的方法上设置[OutputCache]属性,这将覆盖基类上的属性。

    [OutputCache(NoStore = true, 
                 Duration = 0, 
                 VaryByParam = "*")]
    public abstract class BaseController : Controller
    { 
        // no cache by default
    }
    
    public class MyController : BaseController
    {
        [OutputCache(NoStore = false, 
                     Duration = 60, 
                     VaryByParam = "searchText", 
                     Location = OutputCacheLocation.Any)]
        public PartialViewResult Test(string searchText)
        {
            // this method cached ok
        }        
    }