Using VS2012, I added a caching function from the WebRole property caching tab. In particular, he created the following XML file in web.config:
<dataCacheClients> <tracing sinkType="DiagnosticSink" traceLevel="Error" /> <dataCacheClient name="default"> <autoDiscover isEnabled="true" identifier="[cluster role name]"/> </dataCacheClient> </dataCacheClients>
Good Excellent. I replaced the name of the cluster role with the name webrole, say "helloworld.web". Now when I create a DataCacheFactory or DataCache object:
_dataCacheFactory = new DataCacheFactory(); _defaultCache = _dataCacheFactory.GetDefaultCache(); //Or, just this line _defaultCache = new DataCache(@"default");
I get the following error:
Microsoft.ApplicationServer.Caching.DataCacheException was unhandled HelpLink=http://go.microsoft.com/fwlink/?LinkId=164049 HResult=-2146233088 Message=ErrorCode<ERRCA0021>:SubStatus<ES0001>:Server collection cannot be empty. Source=Microsoft.ApplicationServer.Caching.Client ErrorCode=21 SubStatus=-1 Some notes: IDE: VS2012, Framework: 4.0 AzureSDK: June2012 Local dev machine
What am I missing?
Edit
I got it for work!
I created a DataCacheFactory in the WebRole OnStart method, I moved it to Application_Start in Global.asax and it seems to work.
Sandrino explains why this is so: stack overflow
States
source share