I’ve recently been working with the Azure cache client which, by default, is configured by storing the details in your app.config or web.config.
Now this is great if you’re in the traditional world but for Azure Platform as a service solutions Cloud Configuration is key. It allows you to change settings easily across multiple machines without having to jump into web.configs or redeploy etc.
I wrote the little method below to help me to do this as in my testing I was jumping between a couple of different cache’s regularly.
|/// Wrapper for the cache factory to create a DataCache from Authentication token and discovery url|
|/// <param name="token"></param>|
|/// <param name="discoveryurl"></param>|
|private DataCache CacheFactoryWrapper(string token, string discoveryurl)|
|DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration();|
|config.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, discoveryurl);|
|config.SecurityProperties = new DataCacheSecurity(token);|
|DataCacheFactory cacheFactory = new DataCacheFactory(config);|
|DataCache cache = cacheFactory.GetDefaultCache();|
You can then use the CloudConfigurationManager to retreive the info needed then call into the method to start using the cache:
You may want to alter to use something other than the “GetDefaultCache” method but hopefully a good starting point.
[This method was tested in a limited way, double check it makes sense for you before going nuts and putting it into prod!]