添加缓存
1.添加命名空間 using System.Web;
2. ??? public string GetLeaderInfo(string symbol)
??????? {
??????????? //獲取高管信息的路徑??????? ?
??????????? XElement ele = XElement.Load("path.xml");
??????????? string path = ele.Element("leader").Value;
??????????? //首次讀取緩存
??????????? string jsoncache = HttpRuntime.Cache.Get(symbol) as string;
??????????? if (jsoncache == null || jsoncache.Equals(""))
??????????? {
??????????????? //讀取數據
??????????????? XmlDocument doc = new XmlDocument();
??????????????? doc.Load(path);
??????????????? string strSearch = "root/高管信息[@代碼='" + symbol + "']";
??????????????? XmlNode searchNode = doc.SelectSingleNode(strSearch);
??????????????? XmlElement element = (XmlElement)searchNode;
??????????????? xmltoJson json = new xmltoJson();
??????????????? jsoncache = json.XmlToJSON(element);
??????????????? //加緩存
??????????????? HttpRuntime.Cache.Insert(symbol, jsoncache, null, DateTime.UtcNow.AddMinutes(2), System.Web.Caching.Cache.NoSlidingExpiration);
??????????? }
??????????? return jsoncache;
??????? }
轉載于:https://www.cnblogs.com/xuebingz/archive/2011/07/20/2111423.html
總結
- 上一篇: C++学习笔记—srand()和rand
- 下一篇: inotify之文件系统事件监控使用入门