I have a website where I cache a lot of info. I am seeing conflicting information around storing stuff in the asp.net cache.
For example lets say I have this data structure:
Dictionary<string, List<Car>> mydictionary;
I could store the whole thing with a string key as "MyDictionary" and then drill down once i pull out the object.
HttpContext.Cache.Add("MyDictionary",
mydictionary,
null,
Cache.NoAbsoluteExpiration,
new TimeSpan(10, 0, 0),
CacheItemPriority.Normal,
null);
var myDict = HttpContext.Cache["MyDictionary"] as Dictionary<string, List<Car>>;
The other thing i could do is break it down and store each item in my dictionary separately in the cache (given the cache is a dictionary anyway).
Dictionary<string, List<Car>> mydictionary;
foreach (var item in mydictionary.Keys)
{
HttpContext.Cache.Add(item, mydictionary[item], null, Cache.NoAbsoluteExpiration, new TimeSpan(10, 0, 0), CacheItemPriority.Normal, null);
}
var myitem = "test";
var myDict = HttpContext.Cache[myItem] as List<Car>;
Would the performance implication be very different (given i am assuming that everything is in memory anyway ?)