Clicky

iOS Dev Nugget 81 TMCache For In-Memory and Disk-backed Caching

.

Need to run a code review on your codebase? Hire me

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

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues