I have the concept of a Session which stores objects in various states.
Sometimes I need to scan the Session for objects matching a particular query but I do this a lot and performance testing has shown it is becoming a bottleneck in some areas.
Therefore I would like to introduce the concept of indexes on a Session.
Something like...
public IDictionary<K, V> GetIndex<K, V>(Func<V, K> keySelector)
However I'm not sure about how to test "equality" of a Func like this. Obviously I want the index to only be built on the first call to GetIndex and subsequent calls to not build it again.
How should I be mapping these internally to do index existence lookups?
IDictionary<???, IDictionary<K, V>> indexes = ...
Basically how should I be storing the ???. Maybe I can't do this using a Func but perhaps there is some other way.