Looking for a dictionary or similar that automatically removes entries after a specific amount of time, either if they're not used for X amount of time, or simply removed after X amount of time regardless of use.
Before I roll my own I was wondering if C# already has this capability in one of its collections. I haven't seen anything on google but I wanted to check.
You can find MemoryCache from System.Runtime.Caching. Although it isn't generic (if you're using value types, this may be something to consider), it has the TTL mechanism you're looking for.
System.Runtime.Caching.MemoryCache - for .NET Framework applications.
System.Web.Caching.Cache - for ASP.NET applications.
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