我将使用VS2012,在WebRole属性缓存选项卡中添加了缓存功能。它会在web.config中生成以下XML代码:
<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>
好的,太棒了。我用Web角色的名称替换了[集群角色名称],比如“helloworld.web”。现在,当我创建DataCacheFactory或DataCache对象时:
_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
我错过了什么?
编辑
我让它工作了!
我在WebRole OnStart方法中创建了DataCacheFactory,我将其移动到Global.asax中的Application_Start中,看起来它正在工作。
Sandrino解释了为什么会出现这种情况:https://dev59.com/-WfWa4cB1Zd3GeqPdhd9#11886136