[英]C# Using OutputCache in MVC3 Project
我正在使用MCV3 OutputCache来减少包含数据表的页面的加载时间。 我使用ajax方法来更新信息并操纵DOM,以向用户显示其更改已成功。 这很好,直到他们加载页面并加载缓存的数据集而不是更新的数据集。
当调用Update方法时,我想清除或删除缓存,以便在页面重新加载时使用新的更新数据重新创建它。
我的代码如下:
[OutputCache(CacheProfile = "VideoIndexView")]
public ActionResult Index()
{
...
return View(model);
}
当您想从缓存中清除一些URL时,可以调用RemoveOutputCacheItem静态方法。
您可以使用“ Index
操作结果来加载屏幕模板,并使用AJAX来获取和加载实际数据。
[OutputCache(CacheProfile = "VideoIndexView")]
public ActionResult Index()
{
...
return View(model); // Really only return a model that is okay to be cached
}
public ActionResult LoadData ()
{
var Result = // Load the data
...
return Json(Result); // Don't forget to allow GET here if you're using HTTPGET
}
// Or...
public ActionResult LoadData ()
{
var Result = // Load the data
...
return PartialView (Result);
}
这样,可以很好地缓存Index
并且在将页面提供给用户之后,数据将被加载并注入到页面中。 如果要使用类似jQuery的内容,请确保告诉它不要使用GET缓存的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.