Author uses the following code to purge cached items:
Code:
protected static void PurgeCacheItems(string prefix)
{
prefix = prefix.ToLower();
List<string> itemsToRemove = new List<string>();
IDictionaryEnumerator enumerator = BizObject.Cache.GetEnumerator();
while (enumerator.MoveNext())
{
if (enumerator.Key.ToString().ToLower().StartsWith(prefix))
itemsToRemove.Add(enumerator.Key.ToString());
}
foreach (string itemToRemove in itemsToRemove)
BizObject.Cache.Remove(itemToRemove);
}
Is there a reason why we couldnât instead use the following code to purge cached items:
Code:
protected static void PurgeCacheItems(string prefix)
{
prefix = prefix.ToLower();
foreach(DictionaryEntry item in Cache)
{
if(item.Key.ToString().ToLower().StartsWith(prefix))
BizObject.Cache.Remove(item.Key.ToString();
}
}
If both approaches are fine, then why did the author decide to use the more complicated approach?
I would appreciate a bit of help