Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

my application read the outdated data from the xml file

I read data from xml file like this :

StringBuilder str = new StringBuilder();
str.Append("<News>");

XDocument xmlDoc = XDocument.Load(path);
var q = xmlDoc.Descendants("news")
 .Where(x => x.Descendants("language_id") != null && x.Descendants("language_id").First().Value == "2")
 .Select(x => x);

foreach (var st in q)
{
    str.Append(st.ToString(SaveOptions.DisableFormatting) + " ");
}

str.Append("</News>");
return str.ToString();

but I note recently that when the xml file updated. It still reads the data from the old one !!! I don't know if it reads from a cashing copy or not .

When I reset the iis it updates the data .

How to fix this problem?

like image 873
Anyname Donotcare Avatar asked Feb 19 '23 07:02

Anyname Donotcare


1 Answers

Probably you need setup the DefaultCachePolicy.

WebRequest.DefaultCachePolicy = new
RequestCachePolicy(RequestCacheLevel.Revalidate);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(myUri);

From here: http://www.pcreview.co.uk/forums/stop-xmldocument-load-using-cached-data-t3489418.html

like image 135
athoik Avatar answered Mar 02 '23 23:03

athoik