Introducing Azure Colonized Caching

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]"/> <!-- <localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" /> --> </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

+7
source share
3 answers

In your question, you are talking about adding XML to web.config , this works for a web application hosted in your web role (therefore, the code works when used in the Application_Start method).

But you need to know that the code in WebRole.cs starts in another process (even before the web application starts). That is why it cannot read from your web.config and that is the reason why the server did not seem to be configured.

For this code to work with your WebRole.cs, you need to add XML to the configuration file for the process that runs this code. Your code works in WaIISHost.exe , so you need to create a new WaIISHost.exe.config configuration file , add XML to this file and change Copy to Output Directory for this file to "Always Copy."

More on this process WaIISHost.exe: IIS New Features: Differences from Hosted Web Kernel

+6
source

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.

+1
source

Yes. A step though the various configurations, and I reinstalled Azure Tools, as well as during my troubleshooting.

There is the Web.config mentioned above, but in the definition of your service, make sure it has the line:

 <Import moduleName="Caching" /> 

This was my main problem, but then almost everything changed, trying to make it work. In addition, when I watched the web role, the Caching tab was missing, which was fixed by reinstalling the Azure tools (I cleared the old ones that might or might not have helped). I initiated it through sample Azure sites, not above.

 DataCache AgencyCache = new DataCache("AgencyDataValidation"); 

Save Import:

 using Microsoft.ApplicationServer.Caching; 
+1
source

All Articles