0

I have an MVC4 app with asp.net with jquery the project load all pages at firs time then update contents via ajax.

After log off of the app, all pages remain on cache. It cause that in the next login, new data are mixed with old data or some data are repeated.

How can I do to delete all cache at log off?

Juan Pablo Gomez
  • 5,203
  • 11
  • 55
  • 101

1 Answers1

1

I am assuming the the browser is the one caching the page. If this is the case, you can't simply remove the cache from the browser when they log off.

Instead, you will need to tell the browser to not cache any of the pages.

You can do this with a simple action filter and override the OnResultExecuting method

    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
        filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);

        base.OnResultExecuting(filterContext);
    }
Andy T
  • 10,223
  • 5
  • 53
  • 95