我有一個在ASP.Net MVC工作的電子商務。我正在使用緩存來提高頁面的性能,並且它正在工作。視圖中的對象或輸出緩存:哪個更好?
我想鏈接到知道什麼提供了更好的性能,例如,我可以在我的意見設置的OutputCache和並使用該緩存的所有頁面OR我能得到我的產品列表中的控制器,把它放在高速緩存(如下面的代碼)並將其發送到View以呈現給用戶?
private IEnumerable<Products> GetProductsCache(string key, ProductType type)
{
if (HttpContext.Cache[key] == null)
HttpContext.Cache.Insert(key, ProductRepository.GetProducts(type), null, DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration);
return (IEnumerable<Products>)HttpContext.Cache[key];
}
public ActionResult Index()
{
var home = new HomeViewModel()
{
Products = GetProductsCache("ProductHomeCache", ProductType.Product)
Services = GetProductsCache("ServiceHomeCache", ProductType.Service)
};
return View(home);
}
這兩個工作,但我想知道什麼是提高性能的首選方法,或者有其他更好的方法來做到這一點?