I'm trying to find a way to make the .net 4.0 MemoryCache.Default instance use a case insensitive comparer.
Is that possible?
var bob = new object();
MemoryCache.Default["Bob"] = bob;
bob == MemoryCache.Default["bob"]; --> true
From looking at the code through ILSpy, it doesn't appear to be possible. Because behind the scenes it is ultimately using the GetHashCode()
of your key string.
I think the easiest work-around for this, is to implement a custom cache, extending MemoryCache
that overrides all methods that interact with the key, and calls ToUpperInvariant()
when passing it as parameter to the base call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With