我有一个在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);
}
这两个工作,但我想知道什么是提高性能的首选方法,或者有其他更好的方法来做到这一点?