title: Thread-safe caching in ASP.NET HttpModules
body: <h2>Here's the scenario</h2>
  
  <p>I have an ASP.NET 4.0 application which has a LOT of legacy URL rewrites. I want to build an HTTP module that will look at a database of these rewrites and do a 301 redirect if needed. There's tens of thousands of records in this table. </p>
  
  <p>So obviously I need to do some sort of caching so I'm not hitting the database and searching through all those records for each page request.</p>
  
  <p>One of our requirements is to have a fast start up time when our application recycles for some reason (worker process recycles or what have you). So I don't want to load the whole table at app start up. The app start up is already excruciatingly slow.</p>
  
  <p>My brilliant/ridiculous idea is to, </p>
  
  <ol>
  <li>At app start up in my HttpModule create an empty dictionary to hold rewrites.</li>
  <li>Start a background worker thread. The app continues starting up.</li>
  <li>The background worker thread updates the dictionary with say, oh, the most 1000 most used rewrites. </li>
  </ol>
  
  <h2>Questions</h2>
  
  <p>My questions are: </p>
  
  <ol>
  <li>Is this ridiculous?</li>
  <li>Is there such a thing as
  a thread-safe dictionary? The
  background thread might be updating
  the dictionary while new requests
  are coming in. </li>
  <li>Would all the locking
  that goes on in a thread-safe
  collection slow down incoming requests?</li>
  </ol>
  
  <p>Thanks!!</p>