In our ASP.NET application we have DropDownLists with standard values from reference data(e.g list of Countries).
And we used Cache to avoid re-loading them from the database. The function was like the following:
private void LoadItems()
{
ListItem[] cachedItems;
cachedItems = GetAppCacheItems();
if (cachedItems == null)
{
//Load the reference data from the database omitted for simplicity
SetAppCacheItems(cachedItems);
}
Items.Clear();
Items.AddRange(cachedItems);
}
And this method worked for a long time. Unfortunately, some users complained that sometimes combo-boxes showed values, different from what they selected. Delelopers tried to reproduce the problem on the development machines without success.
I've wrote
Watin test case trying to reproduce the problem, and it helped me to find the cause.
ListItem includes
Selected property and keeping it in a cache effectilely shares the selection between all users. If one user selected AU as country, but other user selected US at the same time, the first user can see US as his selection.
I had to change code to recreate ListItems for each request.
posted @ Friday, September 07, 2007 2:15 PM