NSCache

Linked

Poor NSCache, always being overshadowed by NSMutableDictionary. It's as if no one knew it was there, ready to provide all of that garbage collection behavior that developers take great pains to re-implement themselves.

That's right: NSCache is basically just an NSMutableDictionary that automatically evicts objects in order to free up space in memory as needed. No need to respond to memory warnings or contrive a cache-clearing timer mechanism. The only other difference is that keys aren't copied as they are in an NSMutableDictionary, which is actually to its advantage (no need for keys to conform to NSCopying). If developers only knew...

Mattt Thompson, NSHipster

Myself included. Todo: Rewrite Streetmate timeline caching using NSCache, now.

If you enjoy reading you should follow @totocaster on Twitter. In case you have something to add and/or provide feedback—feel free to do so by writing to toto@totocaster.com. For more articles and linked resources subscribe to myRSS feed.