2

I am a beginner in ASP.Net MVC 5. And I have applied caching in certain controller actions. Now I want an action to clear the client cache. How to achieve it. Here is what I have now:

[OutputCache(Duration = 10800, Location = OutputCacheLocation.Client)]
public PartialViewResult Temp()
{
    return PartialView("Index", data);
}

Link I looked: ClearCache

It has a solution which tells to use: Response.Cache.SetNoStore

But it will tell client to never cache right? I am lost here. Please guide me. Under certain scenario only I want the cache to get cleared. In other scenarios caching should take place as expected.

Community
  • 1
  • 1
Unbreakable
  • 6,201
  • 15
  • 62
  • 126

1 Answers1

0

Add this meta tag in your layout page (in html head):

  <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />

and also add golbal.asax.cs:

 protected void Application_AcquireRequestState(Object sender, EventArgs e)
        {
            HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
            HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
            HttpContext.Current.Response.AddHeader("Expires", "0");
     }
Ashiquzzaman
  • 4,409
  • 3
  • 22
  • 34