I’m working with the .NET 4.0 MemoryCache class in an application and trying to limit the maximum cache size, but in my tests it does not appear that the cache is actually o
I know this answer is crazy late, but better late than never. I wanted to let you know that I wrote a version of MemoryCache that resolves the Gen 2 Collection issues automatically for you. It therefore trims whenever the polling interval indicates memory pressure. If you're experiencing this issue, give it a go!
http://www.nuget.org/packages/SharpMemoryCache
You can also find it on GitHub if you're curious about how I solved it. The code is somewhat simple.
https://github.com/haneytron/sharpmemorycache