Is a Swifty version of
NSCache on the cards for Foundation?
NSCache is great for its thread safe behavior and support for automatic purging of items under memory pressure. Unfortunately it doesn't fit so nicely into the type-safe and value type world of Swift. In particular, although it supports lightweight Objective-C generics that are bridged to Swift, it requires that the
ObjectType be Objective-C classes.
This means you can't store Swift Foundation value types like
Data in an
NSCache and instead have to use/bridge to
NSData and the like.
To use it more "generically" with Swift you have to wrap
NSCache in some sort of Swift wrapper that bridges the worlds. This sort of thing would be easy to get wrong and seems like an ideal candidate for Swift's Foundation wrappers. A
Cache class in Foundation would be rad.