[英]Data structure to store client data retrieved from a Web Service
In a web application I invoke a web service to get metadata of documents related to a specific client. 在Web应用程序中,我调用Web服务以获取与特定客户端有关的文档的元数据。 This call might return a set of document records between 10 and 300. I would like to store the retrieved data in a Dictionary (Key = docID - Value = metadata as complex class) and check first for the document ID into the Dictionary.
此调用可能返回10到300之间的一组文档记录。我想将检索到的数据存储在Dictionary中(键= docID-Value =元数据作为复杂类),然后首先检查Dictionary中的文档ID。 Only if not found, then I would call the web service (and update then the dictionary).
只有找不到时,我才调用Web服务(然后更新字典)。
How could I maintain that data structure within the users session? 如何在用户会话中维护该数据结构?
Different users can access the application and request data about different (or same) clients. 不同的用户可以访问该应用程序并请求有关不同(或相同)客户端的数据。 There will be max 40 users connected in the same moment.
同一时间最多可连接40个用户。
How safe/performant would be to create a singleton class to manage this data structure? 创建一个单例类来管理此数据结构的安全性/性能如何? Moreover avoiding it will grow too much.
此外,避免它会增长太多。
Does anyone know a good practice in this scenario? 有谁知道在这种情况下的良好做法?
I would use the Cache to store the Dictionary
. 我将使用Cache来存储
Dictionary
。 The Cache
is application-wide shared across all Sessions
. Cache
是所有Sessions
之间在应用程序范围内共享的。
if(Cache["Documents"] != null){
var dict = (Dictionary<int,YourClass>)Cache["Documents"];
if(!dict.ContainsKey(documentID)){
dict.Add(documentID, yourComplexClass);
}
}else{
var dict = new Dictionary<int,YourClass>();
dict.Add(documentID, yourComplexClass);
Cache.Insert("Documents", dict);
}
You can store the dictionary in session. 您可以将字典存储在会话中。
not sure where a singleton would come into this - just use the session manager. 不知道单例会出现在哪里-只需使用会话管理器即可。
see http://msdn.microsoft.com/en-us/library/ms178581.aspx 参见http://msdn.microsoft.com/en-us/library/ms178581.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.