apple / swift-algorithms

Commonly used sequence and collection algorithms for Swift
Apache License 2.0
5.9k stars 435 forks source link

FR: Add a LRU Cache debatable and predictable. wit #231

Open jesus-mg-ios opened 2 months ago

jesus-mg-ios commented 2 months ago

Hi Community,

I’ve been exploring the inner workings of NSCache and found it to be somewhat unpredictable and challenging to debug, lacking robust methods for effective cache management.

This led me to wonder: would it be feasible to introduce a thread-safe, manageable, and predictable LRUCache that can listen for system low memory warnings and respond according to customizable configurations? The key requirement is that this cache should remain in memory and not be evicted when the system goes into the background or the device is locked.

Creating a custom cache or relying on third-party solutions is quite cumbersome. In my opinion, Apple should address this gap. It’s increasingly uncommon for apps not to require such in-memory caching capabilities.

It would be great to develop a solution here, and perhaps Apple could eventually integrate it into the Foundation framework.

Best.