How would you implement a cache class that supports timeouts using the new Concurrent Collections of .Net 4?
The cache class will be typically holding hundreds of thousands of entries. A very large part of the cache may expire simultaneously.
Unlike a typical web cache, which may shrink due to memory pressure, this class should only automatically remove objects if they time out.
Why do you need to implement a custom caching class? Isn't the default implementation enough? There's a whole new assembly dedicated to caching in .NET 4.0. Example of caching a value for 10 minutes:
var cache = MemoryCache.Default;
cache.Add("key", new object(), DateTime.Now.AddMinutes(10));
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