Hello, Welcome to my blog. If you like feel free to refer others

Tuesday, 3 September 2013

Remove cache in asp.net

The following code will remove all keys from the cache:
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()){
    // delete every key from cache
    for (int i = 0; i < keys.Count; i++) {

Modifying the second loop to check the value of the key before removing it should be trivial.
Hope this helps.