title: Least intensive way of updating cache object from ef list
body: <p>I'm relatively new to ef and would like to ask for some advice.</p>
  
  <p>I have a standard entity framework with very short lived contexts with a requirement for one page to be updated every couple minutes for each user.</p>
  
  <p>This page relies on data from a table which has 500k+ rows which won't change or be added to very often, so I want this data to be stored in memory rather then pulling the data each refresh....</p>
  
  <p>So what I am looking for is to cache this data in a application level List object but on each request for this information for the cache to be checked and if there are any deltas then only those be queried and updated in the cache rather then pulling the whole table and processing one by one.</p>
  
  <p>So for example.</p>
  
  <pre><code>List&lt;T&gt; cache_list; 
  public List&lt;T&gt; getdata()
  {
       if (cache_list != db.table.ToList())
       {
          cache_list.AddRange(db.table.Except(cache_list).ToList())
       }
    return cache_list;
  }
  </code></pre>
  
  <p>I know this will add any new records to the cache but will not update existing rows. Also I think this will be intensive because (and I could be wrong here) either It will have to send the cache to the db or download the whole table before comparing to the other.</p>
  
  <p>Any advice on the best way of doing this?</p>
  
  <p>Edit:
  I'm not actually pulling all 500k rows for the page maybe 500 after being filtered but pulling 500 is still more intensive then either no query because the cache is correct or pulling a couple changes especially when lots of users are on he page at the same time.</p>