In #39: Use NSCache Instead of NSMutableDictionary When Caching, we mentioned using NSCache
for caching. Sometimes, you want a caching system that persists across app restarts, e.g. downloaded photo thumbnails.
TMCache, an open source library from Tumblr that is disk-backed, and the objects stored only need to conform to NSCoding (so everything that goes into plists, such as NSArray
, NSDictionary
, NSString
, NSNumber
, UIImage
, NSData
, already works).
Writing:
[[TMCache sharedCache] setObject:anImage forKey:@"someImage" block:nil];
Reading:
[[TMCache sharedCache] objectForKey:@"someImage"
block:^(TMCache* cache, NSString* key, id object) {
UIImage* image = (UIImage*)object;
}];
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.
.