简体   繁体   English

数据结构,用于存储从Web服务检索到的客户端数据

[英]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.

相关问题 以编程方式创建和存储从Web服务检索为byte []数据的图像作为Umbraco中的媒体项 - Programmatically create and store images retrieved as byte[] data from a web service as media items in Umbraco 将从 web 服务参考检索到的数据存储为数组/数组列表 - Storing data retrieved from web service reference as array/arraylist 如何从Java客户端向C#Web服务发送数据 - How to send data to c# web service from java client 将数据对象列表从客户端发送到Web服务 - Send list of data object from client to web service 来自Web服务的文本块数据 - textblock data from web service 在C#Web方法中,是否可以存储通过Entity Framework检索的数据以进行后续调用? - In a C# Web Method is it possible to store data retrieved via Entity Framework for subsequent calls? 在web.config中存储一系列值-使用哪种数据结构 - Store a range of values in web.config - what data structure to use 我是否正确使用WCF服务从客户端接收数据并将其存储在数据库中? - Am I using the WCF service correctly to receive data from client and store it in database? 从JSON获取数据,存储在IsolatedStorageSettings.ApplicationSettings中,在检索JSON时检索数据 - Get data from JSON, store in IsolatedStorageSettings.ApplicationSettings, retrieve data when JSON is retrieved 从ListView检索错误的数据 - Erroneous Data Retrieved From ListView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM