title: Azure caching of of securitytoken
body: <p>How do you setup shared caching with a dedicated cache worker role and multiple instances of a webrole?  dotnet 4.5.1 mvc 5.1.  </p>
  
  <p>I have a sessiontoken i'm trying to use for authentication/authorization.  The token has a long validto/from times.</p>
  
  <pre><code>                var sessionToken = new SessionSecurityToken(principal)
                  {
                      IsReferenceMode = true,
                  };
  
                  FederatedAuthentication.WSFederationAuthenticationModule.
                      SetPrincipalAndWriteSessionToken(sessionToken, true);
  </code></pre>
  
  <p>I added a cache worker role and configured it by enabling cache and setting it to dedicated.  It created a default named cache setting with 30min sliding window LRU policy.</p>
  
  <p>In my web.config of my webroles</p>
  
  <pre><code> &lt;sessionState mode="Custom" customProvider="SessionProvider"&gt;
        &lt;providers&gt;
          &lt;add name="SessionProvider" 
               type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache" 
               cacheName="default" 
               dataCacheClientName="default" 
               applicationName="MyApp"/&gt;
        &lt;/providers&gt;
      &lt;/sessionState&gt;
  
    &lt;dataCacheClients&gt;
      &lt;dataCacheClient name="default"&gt;
        &lt;autoDiscover isEnabled="true" identifier="CacheWorkerRole" /&gt;
      &lt;/dataCacheClient&gt;
    &lt;/dataCacheClients&gt;
  </code></pre>
  
  <p>It seems to work with one instance, but fails when I introduce more.  It seems to work for a minute or two then it vanishes. Like one instance is not aware of the cache.  Even if I click around a bit to try to get to the first instance it appears to be gone.  </p>
  
  <p>It seems that I can add/read things from the cache manually from each instance.  </p>
  
  <p>I must have WIF or Caching misconfigured.</p>
  
  <p>Ideas?</p>
  
  <p>Thanks</p>