azure - 在 Azure Service Fabric 中实现缓存

标签 azure caching azure-service-fabric stateful

我正在开发一个项目,其中我经常需要一组数据,目前为了获取这些数据,我必须调用第三方服务,这需要花费大量时间。所以我做什么想要的是维护本地缓存。数据很少修改或几乎恒定。在Azure Service Fabric中实现此目的的最佳方法是什么。我目前正在考虑使微服务有状态。这是最好的方法吗?当节点出现故障时,它应该将其本地缓存复制到其他节点。如果使其有状态是好的,那么我应该如何继续实现这个?

最佳答案

好吧,你有两个选择: 如果需要性能和地理缓存数据复制,可以使用 Redis 缓存。

另一个选择是使用可靠的字典。这是一个服务结构功能,可靠的字典被复制到其他节点。

您只能在 Service Fabric 有状态上下文中访问可靠字典。

示例如下:

IReliableDictionary<string, string> Dictionary = await this.StateManager.GetOrAddAsync<IReliableDictionary<string, string>>("stringlistcache");
    using (var tx = this.StateManager.CreateTransaction())
    {   
        await pingDictionary.AddOrUpdateAsync(tx, "testkey", "testvalue", (key, value) => "testvalue");
        cachedValue = await Dictionary.TryGetValueAsync(tx, "testkey");
        await Dictionary.TryRemoveAsync(tx, "testkey");
        await tx.CommitAsync();     
    }

关于azure - 在 Azure Service Fabric 中实现缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44699720/

相关文章:

c# - 安全使用 'HttpContext.Current.Cache'

caching - 为什么 MASKMOVDQU 没有扩展到 256 位和 512 位存储?

python - 找不到资源错误: When Reading CSV from Azure Blob using Pandas with its SAS URL

java - 如何在具有缓存接口(interface)的简单缓存实现中使用泛型?

azure - ARM 模板和针对 AAD 的强制标签值验证

c# - 从异步方法将项目添加到列表

c# - Azure Service Fabric 参与者微服务

c# - 无法在服务结构中使用 DNS 与服务通信

sql - TFS 2015 到 Azure DevOps 迁移

rest - 我想使用 azure storage api 列出容器内的所有子文件夹