title: C# HttpRuntime.Cache
body: <p>I am on Win7 64-bit. This is a rather nasty problem. Here are the steps to reproduce it:</p>
  
  <ol>
  <li><p>Create a new C# Asp.Net project in Visual Studio (I'm using VS 2010, not sure if this matters)</p></li>
  <li><p>In the code behind for Default.aspx, add this code to the <code>Page_Load</code> method</p>
  
  <pre><code>HttpRuntime.Cache.Insert("foo", "test", null, DateTime.Now.AddMinutes(30), TimeSpan.FromMinutes(0));
  
  string p = "var retval; retval = window.showModalDialog('Test.aspx','', 'dialogHeight:100px; dialogWidth: 100px;scroll: no;center: Yes; help: No; resizable: yes; status: no; unadorned: yes;');";
  ScriptManager.RegisterStartupScript(this, GetType(), "openpop", p, true);
  </code></pre></li>
  <li><p>Add another Web Form called Test.aspx. You can put whatever you want in the markup, it's not important.</p></li>
  <li><p>In the code behind for Test.aspx, put this line in the <code>Page_Load</code> method, and set a breakpoint on it.</p>
  
  <pre><code>string x = (string)HttpRuntime.Cache["foo"];
  </code></pre></li>
  <li><p>In the project properties, make sure application is set to run using local IIS Web Server.</p></li>
  </ol>
  
  <p>When you run the project and it hits the breakpoint, step one more time to let it assign x, and then the value of x will be null. At least that's what's happening to me. I don't understand why this is happening, because the value should still be in the cache. In my real application, I also added a callback to HttpRuntime.Cache.Insert to track why the item was not in the cache, and it said it had expired. But if I gave it a 30 minute absolute expiration window, how can it be expired?</p>
  
  <p>Interestingly enough, if you run the application using Visual Studio Development Server instead of IIS, the value is present in the cache! </p>