How can I programmatically clear the cache?

In my application ( ASP.NET + c# ), I need to clear the cache before the user launches the aspx page.

Does anyone know how I can programmatically clear the cache on an aspx page or in the code behind (C #)?

+4
source share
3 answers

Enter the following code into the page load event:

 protected void Page_Load(object sender, EventArgs e) { Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.Now); Response.Cache.SetNoServerCaching(); Response.Cache.SetNoStore(); } 
+11
source

You can remove a page from the output cache as follows:

 HttpResponse.RemoveOutputCacheItem("MyPage.aspx"); 

This will not remove it from any cache on the client side, so if you want to use this technique, you probably want to disable the cache client on the side, for example. using the following directive on an aspx page:

 <%@ OutputCache Location="Server" ... 
+1
source

Unless you have a javascript method to clear the cache (which would be horrible), you cannot.

It is best to ensure that the page does not receive caching at all by doing what the Sukhi offers, or by creating a cache cache profile and using the OutputCache directive.

0
source

Source: https://habr.com/ru/post/1336440/


All Articles