How to to Expire the Output Cache in ASP.NET MVC

You can try this code where you need to define the time interval for caching.

  1. [OutputCache(Location= System.Web.UI.OutputCacheLocation.Server, Duration=3600,VaryByParam="param1;param2")]  

 

you need to expire the Output cache programatically, and it’s not entirely obvious how to do this, so I have documented it, here:

  1. // Get the url for the action method:    
  2. var staleItem = Url.Action("Action""YourController"new    
  3. {    
  4.    Id = model.Id,    
  5.    area = "areaname";    
  6. });    
  7. // Remove the item from cache    
  8. Response.RemoveOutputCacheItem(staleItem);