【发布时间】:2013-08-07 01:11:06
【问题描述】:
我正在尝试在我的辅助角色实例之间设置缓存。为此,我在 Azure 项目中添加了一个新的缓存辅助角色。但是,当我尝试使用以下代码访问默认缓存时:
_dataCacheFactory = new DataCacheFactory();
var cache = _dataCacheFactory.GetDefaultCache();
我永远无法取回默认缓存,并且调用超时。我从 Azure 文档中复制了我的 app.config 文件,并在标识符标签中添加了我的角色名称:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere" />
<section name="cacheDiagnostics" type="Microsoft.ApplicationServer.Caching.AzureCommon.DiagnosticsConfigurationSection, Microsoft.ApplicationServer.Caching.AzureCommon" allowLocation="true" allowDefinition="Everywhere" />
</configSections>
<dataCacheClients>
<dataCacheClient name="default">
<autoDiscover isEnabled="true" identifier="Cache" />
<!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />-->
</dataCacheClient>
</dataCacheClients>
<cacheDiagnostics>
<crashDump dumpLevel="Off" dumpStorageQuotaInMB="100" />
</cacheDiagnostics>
</configuration>
我已经仔细检查了我的缓存工作者角色的名称确实是“缓存”。在我的缓存工作者角色和我的普通工作者角色中,我在配置选项卡的“缓存”选项卡中设置了以下内容:
- 启用缓存
- 缓存集群设置设置为“专用角色”
- 存储帐户凭据:UseDevelopmentStorage=true
我目前正在 Azure Compute Emulator 上运行它。我可以看到我的工作角色和缓存工作角色都已启动并正在运行。是否有一些我遗漏或设置不正确的配置设置?谢谢!
【问题讨论】:
-
请看一下这个线程,看看这是否不是导致您面临的问题的原因:stackoverflow.com/questions/18045279/…。
-
缓存功能仅适用于 Azure,不适用于模拟器。您是否尝试在 Azure 上运行它,您遇到了什么错误?
-
@VladimirDorokhov - 我不确定这个说法是否正确。缓存功能适用于模拟器和云端。
-
谢谢瓜拉夫!将我的 SDK 版本更新到 2.1 似乎已经解决了这个问题。即使在 Azure Compute Emulator 上,我现在也可以访问我的缓存辅助角色。注意事项:NuGet 没有告诉我 Azure SDK 有新版本,因此即使您的 SDK 看起来是最新的,也可能不是。
标签: caching azure azure-worker-roles