public void ClearApplicationCache(){
List<string> keys = new List<string>();
// retrieve application Cache enumerator
IDictionaryEnumerator enumerator = Cache.GetEnumerator();
// copy all keys that currently exist in Cache
while (enumerator.MoveNext()){
keys.Add(enumerator.Key.ToString());
}
// delete every key from cache
for (int i = 0; i < keys.Count; i++) {
Cache.Remove(keys[i]);
}
}
quickmelt
Member
83 Points
60 Posts
how to clear cache in asp.net
Apr 25, 2012 08:18 AM|LINK
hi
can anyone help? there are lots of discussion and forums on how to clear cache but i can't the one that is working.
how can i programatically clear the cache using javascript or C#.net?
thanks
kashif786
Member
312 Points
83 Posts
Re: how to clear cache in asp.net
Apr 25, 2012 08:32 AM|LINK
hi,
You can clear cache by using the following code,
quickmelt
Member
83 Points
60 Posts
Re: how to clear cache in asp.net
Apr 25, 2012 09:48 AM|LINK
i tried that already but it's not working with me
vijay_myl
Contributor
5070 Points
1068 Posts
Re: how to clear cache in asp.net
Apr 25, 2012 02:08 PM|LINK
hi..
Try the below code.
My .NET blog
Submit Article
vijay_myl
Contributor
5070 Points
1068 Posts
Re: how to clear cache in asp.net
Apr 25, 2012 02:09 PM|LINK
Try the above code its working perfectly to remove all the cache
My .NET blog
Submit Article
quickmelt
Member
83 Points
60 Posts
Re: how to clear cache in asp.net
Apr 26, 2012 12:43 AM|LINK
i put that part of the code in my upload button so everytime I click the upload file it will clear the cache, right? but its not working... :-(
quickmelt
Member
83 Points
60 Posts
Re: how to clear cache in asp.net
Apr 26, 2012 01:09 AM|LINK
i tried it again and its deleting the cache but i have to close my browser before it take effect :-(
Richey
Contributor
3816 Points
431 Posts
Re: how to clear cache in asp.net
Apr 27, 2012 08:54 AM|LINK
Hi,
You can try to use HttpRuntime.Close().
http://weblogs.asp.net/atlaszhu/archive/2009/03/09/how-to-dynamically-remove-asp-net-page-output-cache-entries.aspx
http://weblogs.asp.net/morteza/archive/2008/08/11/how-to-remove-all-items-from-cache-memory.aspx
quickmelt
Member
83 Points
60 Posts
Re: how to clear cache in asp.net
May 02, 2012 07:42 AM|LINK
Hi. Do I have to erase my previous code or I will just add this "HttpRuntime.Close()" after?
Below is my code:
public void ClearApplicationCache() { List<string> keys = new List<string>(); IDictionaryEnumerator enumerator = Cache.GetEnumerator(); while (enumerator.MoveNext()) { keys.Add(enumerator.Key.ToString()); } for (int i = 0; i < keys.Count; i++) { Cache.Remove(keys[i]); } }Thanks.