In a web application I invoke a web service to get metadata of documents related to a specific client. 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. Only if not found, then I would call the web service (and update then the dictionary).
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.
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
. The Cache
is application-wide shared across all 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.