I thought about creating some cache helper that gets a Func<T> (or some delegate for .Net2.0)
calculates its hash code (or any other unique string) and if this has code doesn’t exist adds it to the cache.
Is that possible at all?
Does this approach make sense at all?
How can I tell the difference between:
GetCache(() => string.Format("{0}", 1));
And
GetCache(() => string.Format("{0}", 2))
?
You should not use hash codes to determine uniqueness. That’s not what they’re there for.
In your example, the two lambda expressions will end up creating separate methods for the delegates… but it’s quite possible (not guaranteed) that they’d do this anyway even if the code inside was exactly the same. In other words, I think the whole caching idea is fundamentally not going to work in the way that you’re expecting it to.