title: Store a null in System.Web.HttpContext.Current.Cache
body: <p>In an MVC App we are suppose to dynamically load some strings from database. Basically a <code>&lt;string,string&gt;</code> key-value dictionary. Loading each text each time from the database would kill the application, so those texts would normally be pulled from the DB just once and then stored in cache (namely <code>Web.HttpContext.Current.Cache</code>). There are also default texts that are hardcoded and those would be used if nothing was found in the database. To make things more simple I would also put those default texts in the cache.</p>
  
  <p>The logic is as follows:</p>
  
  <ol>
  <li><p>Try getting the text from cache and return it if it's found.</p></li>
  <li><p>If there was no text in the cache, try pulling it from the databaseand and if it's found, save it to cache and return it.</p></li>
  <li>If all above failed, use the default text and save it to the cache so no further queries will be made for this particular key.</li>
  </ol>
  
  <p>If I understand it correctly the only way to check if key is set in <code>Web.HttpContext.Current.Cache</code> is by comparing it's value to a null. My problem is, it's not entirely unlikely that the default text will be a null. So if I put that in the cache, I will not know that the key was set and I will try to pull the non-existant value from the database each time the text is needed.</p>
  
  <p>I know I could use an empty string instead of a null, but it's possible that I might need to distinguish between nulls and empty strings for some reason in the near future.</p>
  
  <p>So is there some way to tell if a key is set in the <code>Web.HttpContext.Current.Cache</code> when the value assigned is a null?</p>