Bot框架维护用户状态 [英] Bot Framework Maintaining User State
问题描述
以前,我使用Microsoft状态服务来维护我的机器人中的用户状态.现在,Microsoft已停止支持状态服务,我已编写了一个静态对象来存储用户数据,如下所示.只想知道这是维护用户状态的正确方法,因为大约有8000个用户可能正在使用该应用程序.我只是担心它是否会引起一些并发.请提出在bot框架中是否存在更好的维护用户状态的方法
Previously i was using Microsoft state service to maintain user state in my bot. Now that Microsoft has stopped supporting state service, i have written a static object to store user data as shown below. Just wanted to know is this a right approach to maintain user state because at once around 8000 user might be using the application. I am just worried if it will cause some concurrent. Please suggest if there is a better way to maintain user state in bot framework
private static object objectLock = new object();
public void SetBotCache(T CaceData, string userID)
{
_sessionData.AddOrUpdate(userID, CaceData, (key, oldValue) => CaceData);
}
public T GetBotCache(string userID)
{
lock (objectLock)
{
if (_sessionData.Count > 0)
{
return _sessionData.First(a => a.Key == userID).Value;
}
else
{
return default(T);
}
}
}
public void RemoveCache(string userID)
{
lock (objectLock)
{
T res;
_sessionData.TryRemove(userID, out res);
}
}
推荐答案
Microsoft Bot Framework工程师专门为此目的提供了 BotBuilder-Azure : https://github.com/Microsoft/BotBuilder-Azure https://www.nuget.org/packages/Microsoft.Bot.Builder .Azure/
The Microsoft Bot Framework engineers have provided BotBuilder-Azure specifically for this purpose: https://github.com/Microsoft/BotBuilder-Azure https://www.nuget.org/packages/Microsoft.Bot.Builder.Azure/
Bot Framework博客还提供了有关如何设置 Azure Table存储和 DocumentDb (现在为 CosmosDb )的说明: https://blog.botframework.com/2017/07/18/saving-state-azure-extensions/
The Bot Framework blog also provides instructions for how to setup Azure Table Storage and DocumentDb (now CosmosDb): https://blog.botframework.com/2017/07/18/saving-state-azure-extensions/
这篇关于Bot框架维护用户状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!