Reputation: 7051
I am using MCV3 OutputCache to decrease the loading times of a page with a table full of data. I use ajax methods to update information and manipulate the DOM to show the user that their change has been succesful. This is fine until they load the page and the cached dataset is loaded instead of the updated one.
When the an Update method is called I would like to clear the cache or remove it, so that it is recreated on reload of the page, with the new updated data.
My code is as follows:
[OutputCache(CacheProfile = "VideoIndexView")]
public ActionResult Index()
{
...
return View(model);
}
Upvotes: 0
Views: 638
Reputation: 1038720
You could call the RemoveOutputCacheItem static method when you want to clear some url from the cache.
Upvotes: 1
Reputation: 3952
You could use your Index
action result to load a template of the screen and use AJAX to get and load the actual data.
[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);
}
This way, Index
can be cached just fine and the data will be loaded and injected into the page after the page has been served to the user. If you are going to use something like jQuery, be sure to tell it not to use cached results if you're using GET.
Upvotes: 0