This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Description
It may be possible to significantly improve the performance of MemoryCache by using ConcurrentDictionary rather than Dictionary protected by a ReaderWriterLockSlim. Under high load, there is contention acquiring the read lock from ReaderWriterLockSlim.
I created a quick prototype which shows significantly improved performance, though it may not be functionally correct in all scenarios.
| Scenario |
MemoryCache Implementation |
RPS |
CPU |
| Plaintext |
N/A |
1,167,369 |
100% |
| MemoryCachePlaintext |
ReaderWriterLockSlim |
342,129 |
60% |
| MemoryCachePlaintext |
ConcurrentDictionary |
802,076 |
100% |
The remaining work is to improve and test the ConcurrentDictionary implementation to ensure it's correct under high load, has no race conditions, etc.
Prototype: https://github.com/aspnet/Caching/tree/mikeharder/concurrent-dictionary