An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

ASP.NET 2.0: XmlDataSource - Default Caching Feature

Friday, April 28, 2006 5:03 AM

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 !!!


Feedback

No comments posted yet.


Post a comment





 

Please add 5 and 8 and type the answer here: