Here is a (greatly simplified) piece of code that has been happily running on 13 production servers for one year.
The above code has a flaw. We can’t depend on a cached object still being in the cache when we are ready to use it. The code assumes it can place an object in the cache and (almost) immediately pull it back out. Even with the flaw, the code never caused a problem in production environments that log all exceptions.
The weird part is that the data.ToString() line occasionally throws a NullReferenceException on one (and only one) developer machine. How odd that the code fails on a developer machine serving a single request at a time. It’s good the weirdness occurred, because it pointed out a problem. The fix is to return a reference from the initialize cache method, and not to depend on the ASP.NET cache to keep the object alive.