0

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?

hs2d
  • 6,027
  • 24
  • 64
  • 103
  • The question is not about what i have tried. The question is about getting some ideas what would be a good way to do this! – hs2d Oct 06 '11 at 19:07

2 Answers2

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));
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
LoveMeSomeCode
  • 3,888
  • 8
  • 34
  • 48
  • Yes, that's probably the most common solution, yet maybe there is some better ones.. (: – hs2d Oct 06 '11 at 19:19
  • 1
    I think you need to refine your question. There are several ways to do this, but 'best' depends on your requirements. What's most important to you in your scenario? – LoveMeSomeCode Oct 06 '11 at 19:40
0

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"); 
} 
James Johnson
  • 45,496
  • 8
  • 73
  • 110