title: Strategies for "Pre-Warming" an ASP.NET Cache
body: <p>I have an ASP.NET MVC 3 / .NET Web Application, which is <em>heavily</em> data-driven, mainly around the concept of "Locations" (New York, California, etc).</p>
  
  <p>Anyway, we have some pretty busy database queries, which get cached after they are finished.</p>
  
  <p>E.g:</p>
  
  <pre><code>public ICollection&lt;Location&gt; FindXForX(string x)
  {
     var result = _cache.Get(x.ToKey()) as Locaiton; // try cache
  
     if (result == null) {
        result = _repo.Get(x.ToKey()); // call db
        _cache.Add(x.ToKey(), result); // add to cache
     }
  
     return result;
  }
  </code></pre>
  
  <p>But i don't want to the unlucky first user to be waiting for this database call.</p>
  
  <p>The database call can take anywhere from 40-60 seconds, well over the default timeout for an ASP.NET request.</p>
  
  <p>I want to "pre-warm" these calls for certain "popular" locations (e.g New York, California) when my app starts up, or shortly after.</p>
  
  <p>I don't want to simply do this in <strong>Global asax</strong> (Application_Start), because the app will take too long to start up. (i plan to pre-cache around 15 locations, so that's a few minutes of work).</p>
  
  <p>Is there any way i can fire off this logic asynchronously? Maybe a service on the side is a better option?</p>
  
  <p>The only other alternative i can think of is have an <strong>admin page</strong> which has buttons for these actions. So an administrator (e.g me) can fire off these queries once the app has started up. That would be the easiest solution.</p>
  
  <p>Any advice?</p>