views:

379

answers:

1

My website runs on a single server. I am caching a DataTable. Each session has a refernce to it's own DataView referring to that DataTable. What I am worried about is when I need to make changes to the underlying datatable will they propagate to each of the sessions references to it.

Or is there a better way to handle this situation.

A: 

In principle, yes. Changes will propagate to views provided you continue to use the same DataTable. However there is a potential for problems depending on how you implement this:

  • You have a potential race condition when generating the cached DataTable for the first time: multiple requests to the server may detect that the cached DataTable does not exist, and attempt to generate it - in this case you could have a duplicate DataTable.

  • If you regenerate the cached DataTable (for example if it is removed from the ASP.NET cache due to a timeout expiring), then existing DataViews in Session will continue to reference the old DataTable.

Joe