I have an xml file that will be read many times from the source code. I would like to know the efficient way in which i can read only once [ during application start ] the xml file and then cache its contents so that i can reuse it efficiently and fastly.
I am using C# 4. Kindly suggest the best practice for efficient caching and reading.
EDIT
Found this resource : CodeProject Article
I have loaded the xml file into an XmlDocument and Cached it using Enterprise Library as follows,
XmlDocument xdoc = new XmlDocument();
xdoc.Load("MyXmlFile.XML");
FileDependency fileDependency=new FileDependency("MyXmlFile.XML");
cacheManager.Add("XConfig", xdoc, CacheItemPriority.Normal, null, fileDependency);
To read the xml is XmlReader, look: The most efficient way to parse Xml
And caching use a XmlDocument Object, and keep it in memory: C# Best way to hold xml data
To use both together, look: http://msdn.microsoft.com/en-us/library/a8ta6tz4.aspx
The problem with XmlDocument is to read, not to manipulate, the best way to manipulate is Linq to Xml, that has a good performance as well, but don’t beat the XmlReader, look this comparisons: http://www.nearinfinity.com/blogs/joe_ferner/performance_linq_to_sql_vs.html