Take the 2-minute tour ×  I am working on a .NET 4.0
application, that performs a rather expensive calculation on two
doubles returning a double. This calculation is performed for
each one of several thousand items. These calculations are
performed in a Task on a threadpool thread.  Some preliminary
tests have shown that the same calculations are performed over
and over again, so I would like to cache n results. When the
cache is full, I would like to throw out the least-oftenrecently
used item. (Edit: I realized least-often doesn't make sense,
because when the cache is full and I would replace a result with
a newly calculated one, that one would be least often used and
immediately replaced the next time a new result is calculated
and added to the cache)  In order to implement this, I was
thinking of using a Dictionary<Input, double> (where Input would
be a mini-class storing the two input double values) to store
the inputs and the cached results. However, I would also need to
keep track of when a result was