views:

104

answers:

2

I'm storing a lot of sorted ~10 row 2 column/key value pairs in ASP.NET cache-- they're the data for dropdownlists. Right now they are all DataTables, which isn't very space efficient (the rule of thumb is 10x increase in size when data is strored in a dataset).

Old Code

DataTable table = dataAccess.GetDataTable();
dropDownList.DataSource = table;

Hoped for new Code

Unknown data = dataAccess.GetSomethingMoreSpaceEfficient();
dropDownList.DataSource = data;

What pre-existing datastructures are similar enough to DataTable that would minimize code breakage and reduce the serialized size when stored in ASP.NET cache?

+3  A: 

A Key/Value pair or a Dictionary would be more efficient.

Rick Strahl has a nice example http://www.west-wind.com/Weblog/posts/32508.aspx

hearn
I agree. He also mentioned that the data was sorted; the SortedDictionary or SortedList data structure that might be appropriate for the task.
Dr. Wily's Apprentice
ah yes. forgot to mention the Ready Sorted flavors!
hearn
I'll have to rename all the columns to "Key" and "Value". Current code references everything by Column[0], Column["description"], etc. Still, this is an important candidate data structure.
MatthewMartin
No need to rename, you would just reference them using "Key" dic.Add("LGW", "London Gatwick");dic.Add("MCO", "Orlando Int");this.drpIATA.DataSource = dic;this.drpIATA.DataTextField = "Value";this.drpIATA.DataValueField = "Key";this.lstStates.DataBind();
hearn
A: 

Write data to an XML file,based on Session ID, then bind dropdownlists to the XMLDataSource

Daniel Bern
That is in effect writing a caching system that stores its objects on the file system instead of in memory. Any custom rolled caching system wouldn't need me to re-implement cache eviction policies (re-loading from the database from time to time, etc) and UI for on demand cache eviction, which I've already implemented targeting the ASP.NET cache.
MatthewMartin
XML could be stored in memory and added to cache w/o a lot of work.
Daniel Bern
I think what you need is a good hashing algorithm. SortedDictionary,Dictionary and SortedList have a lot of performance issues that you can find in Google. It makes your work simple, but does not help you with performance problem.
Daniel Bern