I'm writing some code that uses reflection. So I'm trying to cache the expensive processing of the reflection into a ConcurrentDictionary
. However, I want to apply a restriction limit on the concurrent dictionary to prevent storing old and unused cached values.
I did some research on my end to see how to limit the size of the ConcurrentDictionary
. I found some interesting answers, however I don't know if the answers suits my requirements and will perform well.
I found in Dapper source code that they did some custom code to handle the limit of the ConcurrentDictionary
. They have a collection limit constant that they use with Interlocked to be able to the handle the concurrency of the dictionary.
On the other hand, I found an answer on SO, that uses a normal Dictionary and then applies on it a ReaderWriterLockSlim
to handle the concurrency. I don't know if it's the same implementation in .Net source code.
Should I go with dapper implementation or the SO answer implementation?
Aucun commentaire:
Enregistrer un commentaire