title: How to use System.Web.Caching in asp.net?
body: <p>I have a class that looks like this:</p>
  
  <pre><code>using System.Collections.Generic;
  using System.Web.Caching;
  
  public static class MyCache
  {
      private static string cacheKey = "mykey";
  
      public static Dictionary&lt;string, bool&gt; GetCacheValue(bool bypassCache)
      {
          var settings = Cache[cacheKey] as Dictionary&lt;string, bool&gt;; // error on this line
  
          // ...etc...
  
          return settings
      }
  }
  </code></pre>
  
  <p>the problem I'm having is that this wont compile. The compiler says <code>Cache</code> can't be used the way I'm doing it. Here's the message:</p>
  
  <pre><code>'System.Web.Caching.Cache' is a 'type' but is used like a 'variable'
  </code></pre>
  
  <p>This perplexes me. I've googled the ASP.NET Cache API and have found many examples of <code>Cache</code> being used this way. Here's one of those examples:</p>
  
  <pre><code>// http://www.4guysfromrolla.com/articles/100902-1.aspx
  value = Cache("key")
  
        - or -
  
  value = Cache.Get("key")
  </code></pre>
  
  <p>When I try using <code>Cache.Get()</code> I get another error saying that it's not a static method.</p>
  
  <p>Evidently I need to initialize an instance of <code>Cache</code>. Is this the correct way to use this API? A follow-up question is, does cached information persist across instances?</p>
  
  <p>Thanks for your help.</p>