开发者

How to cache XML url?

I am retrieving an XML string through a URL. My code works great, but I do not know how to add caching to it. I am not sure if I am able to cache XML streams or if that is even the right approach. What is the best way to ad开发者_如何学运维d caching here?

XmlTextReader xmlTextReader = new XmlTextReader(this.RssUrl);
XmlDataDocument xdoc1 = new XmlDataDocument();
xdoc1.DataSet.ReadXml(xmlTextReader, XmlReadMode.InferSchema);
return xdoc1.DataSet.Tables["item"];


You could save the XML together with a timestamp, and if you need to reread the XML, you read from the stored XML until the timestamp gets older than a preconfigured value. Most RSS-readers do this to avoid flooding the RSS-service with requests.

Or, if you control the RSSUrl, you could implement the caching there. That would utilize HTTP caching and the fact that the web server can return 304 Not modified if no new items are added to the feed.


Cache the entire XmlDataDocument. If you only cache the XML, you'll have to parse it all the time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜