2009/04/04

Tips: Clean Session/Cache (4/21/2009 updated)

Clean Session:
Session.Clear();
Totally remove the Session:
Session.Abandon();
Clean Cache:
HttpRuntime.Close();
Note: Be careful when using this way to clear the cache (See here). I found a better way to do the same thing from here.
List cacheKeys = new List();
IDictionaryEnumerator cacheEnum = Cache.GetEnumerator();
while (cacheEnum.MoveNext())
{
cacheKeys.Add(cacheEnum.Key.ToString());
}
foreach (string cacheKey in cacheKeys)
{
Cache.Remove(cacheKey);
}

Reference: What is the best way to end session?

No comments:

Post a Comment