I need to cache a large amount of data from a database in an ASP.NET MVC application and would like to use a SortedList. I know that in .NET 4.0 parallel collections are added, but there is no sorting. I thought of using a SynchronizedCollection, but uses locks intensively even for reading (if I'm not mistaken), so I'm looking for other options. Basically, I need a parallel collection with O (log n) access complexity.
EDIT - code based on Greg's answer
void WrappedAdd(TKey k, TValue v)
{
var copy = new SortedList<TKey, TValue>(_sortedList);
copy.Add(k, v);
_sortedList = copy;
}
source
share