![](/img/trans.png)
[英]Programmatically create and store images retrieved as byte[] data from a web service as media items in Umbraco
[英]Data structure to store client data retrieved from a Web Service
在Web應用程序中,我調用Web服務以獲取與特定客戶端有關的文檔的元數據。 此調用可能返回10到300之間的一組文檔記錄。我想將檢索到的數據存儲在Dictionary中(鍵= docID-Value =元數據作為復雜類),然后首先檢查Dictionary中的文檔ID。 只有找不到時,我才調用Web服務(然后更新字典)。
如何在用戶會話中維護該數據結構?
不同的用戶可以訪問該應用程序並請求有關不同(或相同)客戶端的數據。 同一時間最多可連接40個用戶。
創建一個單例類來管理此數據結構的安全性/性能如何? 此外,避免它會增長太多。
有誰知道在這種情況下的良好做法?
我將使用Cache來存儲Dictionary
。 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.