title: What is the most efficient way to store / retrieve items in asp.net httpContext.Cache
body: <p>I have a website where I cache a lot of info.  I am seeing conflicting information around storing stuff in the asp.net cache.</p>
  
  <p>For example lets say I have this data structure:</p>
  
  <pre><code> Dictionary&lt;string, List&lt;Car&gt;&gt; mydictionary;
  </code></pre>
  
  <p>I could store the whole thing with a string key as "MyDictionary" and then drill down once i pull out the object.</p>
  
  <pre><code> HttpContext.Cache.Add("MyDictionary",  
     mydictionary, 
     null, 
     Cache.NoAbsoluteExpiration,
     new TimeSpan(10, 0, 0),
     CacheItemPriority.Normal,
     null);
  
   var myDict = HttpContext.Cache["MyDictionary"] as Dictionary&lt;string, List&lt;Car&gt;&gt;;
  </code></pre>
  
  <p>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).</p>
  
  <pre><code> Dictionary&lt;string, List&lt;Car&gt;&gt; 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&lt;Car&gt;;
  </code></pre>
  
  <p>Would the performance implication be very different (given i am assuming that everything is in memory anyway ?)</p>