Implement Cache in Azure Service Fabric

核能气质少年 提交于 2019-12-06 12:43:47
Renan Fagundes

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!