在Azure Service Fabric中实现缓存

问题描述 投票:2回答:2

我正在开发一个项目,其中我经常需要一组数据,目前我需要调用第三方服务,这需要花费很多时间。所以我想要的是维护本地缓存。数据很少修改或几乎不变。在Azure Service Fabric中实现这一点的最佳方法。我目前正在考虑使微服务具有状态。这是最好的方法吗?当节点关闭时,它应该将其本地缓存复制到其他节点。如果使其成为有状态,那么我应该如何继续实现它?

azure caching azure-service-fabric stateful
2个回答
2
投票

那么,您有两个选择:如果您需要性能和地理缓存数据复制,则可以使用redis缓存。

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

您只能在服务结构有状态上下文中访问可靠字典。

示例:

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();     
    }

0
投票

我知道这篇文章很老了,但对于那些今天寻求解决方案的人来说,你可以使用这个开源项目:

http://service-fabric-distributed-cache.socreate.it

你也可以在GitHub上找到它:https://github.com/SoCreate/service-fabric-distributed-cache

© www.soinside.com 2019 - 2024. All rights reserved.