ASP.NET 2.0: XmlDataSource - Default Caching Feature

XmlDataSource is a wonderful Data Source control used to bind hierarchial data. It can be combined with a TreeView to display a Tree structure of Data to the users.

While implementing XmlDataSource, we may not get the Data updated even though we change the underlying data, due to the built-in caching feature of this control.

Let us examine the following scenario.

We have a XML Fragment retrieved from Database based on a user input and set as the Data for the XmlDatasource. Then, when the user input changes, we would be getting a different XML Fragment from the Database. However, you will find that when you bind the XmlDataSoruce to a control, the data doesnt change.

This is because, by default, the EnableCaching propery is set to "true". You can also find that the CacheDuration is set to "Infinite". This forces the Data in the XmlDataSource to be cached and hence the change in the underlying Data, wont get reflected.

The resolution is to set the EnableCaching property to false or specify a CacheKeyDependency, or set the CacheDuration to a lesser time.

Since it is by default set for caching and we dont explicitly set it, it may be a little surprising to see the stale data when dealing with XmlDataSources.

This is not the same with other DataSources like SqlDataSource, ObjectDataSource etc., which have the EnableCaching property set to false, by default.

Cheers and Happy Programming !!!

Print | posted on Friday, April 28, 2006 5:03 AM

Comments on this post

# re: ASP.NET 2.0: XmlDataSource - Default Caching Feature

Requesting Gravatar...
Thanks for share the information. Very helpful for me!
Left by cheap auto insurance on Jan 27, 2010 6:23 PM

# re: ASP.NET 2.0: XmlDataSource - Default Caching Feature

Requesting Gravatar...
This helped me a lot !!! After 3.5 years of the post !!

Thanks a lot !
Left by Viral on Feb 16, 2010 10:37 PM

Your comment:

 (will show your gravatar)