title: MemoryCache is not keeping the cache between different services for the same IIS site (WebApi 2)
body: <p>My goal using MemoryCache is to prevent the same user to login more than one time in my application.</p>
  
  <p>I have 3 services registered in the same IIS site: user, navigation and evaluation services. I implemented the MemoryCache in my framework which is used as reference between all the services. I have a filter that verify whether I have the user token cached or not for every request made from any service.</p>
  
  <p>When I login in my application, it will send 3 requests: 2 for the 'user' service and 1 for the 'navigation' service. The first request will set the cache using the 'user' service. At this time, I will have my object cached in memory. The second request uses the 'user' service again, which verifies that the token is there and return the result successfully. </p>
  
  <p>My problem: The last request uses the 'navigation' service, and at this point, it can't access the cache (or the cache is no longer available) and throws an exception that I implemented.</p>
  
  <p>IIS Site</p>
  
  <pre><code>Sites
  -&gt; APR
     -&gt; API
        -&gt; User
           -&gt; V1 (application)
        -&gt; Navigation
           -&gt; V1 (application)
        -&gt; Evaluation
           -&gt; V1 (application)
  </code></pre>
  
  <p>Below is my code:</p>
  
  <pre><code>public static CacheItemPolicy policy = new CacheItemPolicy();
  public static MemoryCache cache = MemoryCache.Default;
  
  public static bool GetCache&lt;T&gt;(string key, out T output, T defaultValue)
  {
      try
      {
          output = (T)cache.Get(key);
          if (output != null)
          {
              return true;
          }
      }
      catch { }
  
      output = defaultValue;
      return false;
  }
  
  public static void SetCache(string key, object obj, DateTime date)
  {
      try
      {
          policy.AbsoluteExpiration = date;
          cache.Set(key, obj, policy);
      }
      catch { }
  }
  
  public static void RemoveCache(string key)
  {
      cache.Remove(key);
  }
  </code></pre>