问题
Im requesting data from web service and receive a xml file.Not do flood the service good idea would be to cache/store the xml so when the application is started again it would use that cached xml. The data in received xml will change in every 24 hours so afther that time is passed from old request application must create new one anyway.
What would be the best solution to keep that data?
EDIT: Maybe use SQLite to keep some history?
回答1:
You can just stream it to a file:
/// saving it :
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.IO.File.WriteAllText(filename, doc.Value);
/// loading it back in :
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
xdoc.LoadXml(System.IO.File.ReadAllText(filename));
回答2:
If I'm understanding you correctly, you might consider loading the data into an XmlDocument or XDocument and storing it in cache with a CacheDependency:
XmlDocument xDoc = new XmlDocument();
if (Cache.Get("MenuData") == null)
{
xDoc.Load(Server.MapPath("/MenuData.xml"));
Cache.Insert("SiteNav", xDoc, new CacheDependency(Server.MapPath("/MenuData.xml")));
}
else
{
xDoc = (XmlDocument)HttpContext.Current.Cache.Get("MenuData");
}
来源:https://stackoverflow.com/questions/7679111/c-sharp-best-way-to-hold-xml-data