在Azure Service Fabric中实施缓存 [英] Implement Cache in Azure Service Fabric

查看:74
本文介绍了在Azure Service Fabric中实施缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我经常需要一组数据,而目前要获取这些数据,我必须打电话给3rd Party Service,这花费了很多时间.我想要的是维护本地缓存.数据很少被修改或几乎不变.在Azure Service Fabric中实现此最佳方法是什么?我目前正在思考使微服务有状态.是最好的方法吗?当节点发生故障时,应将其本地缓存复制到其他节点.如果使它有状态比我应该如何继续执行此操作好?

I am working on a project in which I need a set of data frequently and currently for getting that data I have to make call to 3rd party Service which is taking lot of time.So what I want is to maintain a local cache.The Data is modified very infrequently or is almost constant.What is the best way of implementing this in Azure Service Fabric.I am currently thinking of making the Microservice stateful. Is is the best way to do this?When node goes down it should copy its local cache to other node.If making it stateful is good than How should i go on implementing this?

推荐答案

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

Well, you have two options: If you need performance and geografical cache data replication, you can use a redis cache.

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

The other option is use reliable dictionary's. It's a service fabric feature, and reliable dictionary's are replicated to other nodes.

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

You can only access the reliable dictionary in a service fabric statefull context.

以下示例:

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 Service Fabric中实施缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆