title: Storing and Retrieving a list in IMemoryCache
body: <p>I am currently doing the following to store a list in the IMemoryCache:</p>
  
  <pre><code>_memoryCache.Set("PriceList", horsepricelist);
  </code></pre>
  
  <p>And accessing it/returning data:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public PriceResponse.PriceForEntry GetPriceListEntry(DateTime meetingDate, int courseId, int raceNumber, string horseCode)
  {
      var pricelist = _memoryCache.Get("PriceList");
      var dateprefix = "/Date(" + meetingDate.Ticks.ToString() + ")/";
  
      return ((IEnumerable)pricelist).Cast&lt;PriceResponse.PriceForEntry&gt;().FirstOrDefault(x =&gt; x.meetingDate == dateprefix &amp;&amp;
                                                                                              x.courseId == courseId &amp;&amp;
                                                                                              x.raceNumber == raceNumber &amp;&amp;
                                                                                              x.horseCode == horseCode);
  }
  </code></pre>
  
  <p>Return a list without the horsecode:</p>
  
  <pre class="lang-cs prettyprint-override"><code>        public List&lt;PriceResponse.PriceForEntry&gt; GetPriceList(DateTime meetingDate, int courseId, int raceNumber, bool? ShowAll)
          {
             var pricelist = _memoryCache.Get&lt;List&lt;PriceResponse.PriceForEntry&gt;&gt;("PriceList");
             var dateprefix = "/Date(" + meetingDate.Ticks.ToString() + ")/";
  
             return pricelist.Where(x =&gt; x.meetingDate == dateprefix &amp;&amp; x.courseId == courseId &amp;&amp; x.raceNumber == raceNumber).ToList();
          }
  </code></pre>
  
  <p>The viewmodel structure of the list that in held in the cache:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class PriceResponse
  {
      public class PriceForEntry
      {
          public string meetingDate { get; set; }
          public int courseId { get; set; }
          public int raceNumber { get; set; }
          public string horseCode { get; set; }
          public List&lt;Bookmakerprice&gt; bookmakerPrices { get; set; }
      }
  
      public class Bookmakerprice
      {
          public int bookmakerId { get; set; }
          public string bookmakerName { get; set; }
          public string selectionId { get; set; }
          public string fractionalOdds { get; set; }
          public float decimalOdds { get; set; }
          public string bookmakerRaceid { get; set; } //This is the event Id.
          public string bookmakerMarketId { get; set; } //Market Id.
      }
  }
  </code></pre>
  
  <p>Is there a better way to get values such as setting various keys and values in the cache to get an entry rather than converting the object back to the list and looping through it?</p>