title: Best practice when using Azure AppFabric Caching Service?
body: <p>I have successfully started using Azure AppFabric Caching Service, but I' not sure what the best practice way of creating the DataCacheFactory object is. Now I'm creating it for every call into the cache, but apparently this is not the ideal way of doing it... </p>
  
  <p>Some advise call for a Singleton. But I'm not sure I understand how this would be implemented (not the actual Singleton class, but how to tie it all together). </p>
  
  <p>Today I have a CacheProvider class that is created for me using Ninject where I can do Get/Put/Remove operations. For each of these methods I create the DataCacheFactory object and then call .GetDefaultCache() to get the DataCache object, where I call Put/Get/Remove respectively. I do this in a single method that looks like this:</p>
  
  <pre><code>private T Cache&lt;T&gt;(Func&lt;DataCache, T&gt; cacheAction)
  {
      using (DataCacheFactory dataCacheFactory = new DataCacheFactory())
      {
          DataCache dataCache = dataCacheFactory.GetDefaultCache();
          return cacheAction(dataCache);
      }
  }
  </code></pre>
  
  <p>I'm now pretty sure that this is not-so-clever-idea, I should instead be getting the DataCache object via a Singleton where the DataCacheFactory object is just created once. BUT how will that object survive between requests? And how does that work with > 1 instance on Azure?</p>
  
  <p>Hope all this makes sense and that somebody with more experience than me (3 hours) can help me out.</p>