I don't think it is a good idea to cache everything, but you could do it non-LINQ with something like:
var iter = HttpContext.Current.Cache.GetEnumerator(); using (iter as IDisposable) { while (iter.MoveNext()) { string s; if ((s = iter.Key as string) != null && s.Contains("subcat")) {
to do this with LINQ, you can do something like:
public static class Utils { public static IEnumerable<KeyValuePair<object, object>> ForLinq(this IDictionaryEnumerator iter) { using (iter as IDisposable) { while (iter.MoveNext()) yield return new KeyValuePair<object, object>(iter.Key, iter.Value); } } }
and use as:
var items = HttpContext.Current.Cache.GetEnumerator().ForLinq() .Where(pair => ((string)pair.Key).Contains("subcat"));
source share