[英]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.