Implement Cache in Azure Service Fabric

2019-05-28 23:35发布

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?

2条回答
手持菜刀,她持情操
2楼-- · 2019-05-29 00:12

I know this post is quite old, but for those looking for a solution today, you can use this open source project:

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

you can also find it on GitHub here: https://github.com/SoCreate/service-fabric-distributed-cache

查看更多
你好瞎i
3楼-- · 2019-05-29 00:16

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.

Example bellow:

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();     
    }
查看更多
登录 后发表回答