【发布时间】:2011-02-25 12:16:17
【问题描述】:
我有一个在 ASP.Net MVC 中工作的电子商务。我正在使用缓存来提高我的页面性能并且它正在工作。
我会链接以了解什么提供更好的性能,例如,我可以在我的视图中设置 OutputCache 并将此缓存用于所有页面或我可以在控制器中获取我的产品列表,将其放在缓存中(如下面的代码)并将其发送到 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);
}
两者都有效,但我想知道提高性能的首选方法是什么,或者还有其他更好的方法吗?
【问题讨论】:
标签: asp.net asp.net-mvc performance caching