I am writing code that uses reflection. Therefore, I am trying to cache expensive reflection processing in ConcurrentDictionary . However, I want to apply a restriction constraint on a parallel dictionary to prevent old and unused cached values ββfrom being preserved.
I did some research at my end to find out how to limit the size of a ConcurrentDictionary . I found some interesting answers, but I donβt know if the answers meet my requirements and will work well.
I found the source code in Dapper that they made some kind of custom code to handle the ConcurrentDictionary limit. They have a limit collection constant that they use with Interlocked to be able to handle dictionary concurrency.
On the other hand, I found an answer to SO that uses a regular dictionary, and then applies a ReaderWriterLockSlim to it to handle concurrency. I do not know if the same implementation was in the .NET source code.
Should I go with a dapper implementation or an SO response implementation?
source share