Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically clear cache?

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

Does anybody have any idea how I can programmatically clear the cache on an aspx page, or in the code behind (c#)?

like image 786
Jeff Norman Avatar asked Dec 09 '22 11:12

Jeff Norman


1 Answers

Write following code in 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();
}
like image 75
Sukhjeevan Avatar answered Jan 01 '23 04:01

Sukhjeevan