Skip to content
Fast parallel object cache for iOS and OS X.
Objective-C Other
Branch: master
Clone or download
Latest commit 4a39e53 May 13, 2015
Type Name Latest commit message Commit time
Failed to load latest commit information.
TMCache Use separate methods for notification handling, deprecate public meth… May 8, 2015
docs docs formatting May 24, 2013
tests Factor out references to UIApplication Apr 24, 2015
.gitignore .gitignore Dec 22, 2012
.travis.yml travis should only build the master branch [ci skip] Apr 27, 2013 Update CHANGELOG May 8, 2015
LICENSE.txt Update LICENSE.txt Nov 18, 2013 Update May 12, 2015
TMCache.podspec Use separate methods for notification handling, deprecate public meth… May 8, 2015 bump version and build docs May 24, 2013 further mollification Oct 9, 2013



Fast parallel object cache for iOS and OS X.

Build Status Version Platform License

TMCache is a key/value store designed for persisting temporary objects that are expensive to reproduce, such as downloaded data or the results of slow processing. It is comprised of two self-similar stores, one in memory (TMMemoryCache) and one on disk (TMDiskCache), all backed by GCD and safe to access from multiple threads simultaneously. On iOS, TMMemoryCache will clear itself when the app receives a memory warning or goes into the background. Objects stored in TMDiskCache remain until you trim the cache yourself, either manually or by setting a byte or age limit.

TMCache and TMDiskCache accept any object conforming to NSCoding. Put things in like this:

UIImage *img = [[UIImage alloc] initWithData:data scale:[[UIScreen mainScreen] scale]];
[[TMCache sharedCache] setObject:img forKey:@"image" block:nil]; // returns immediately

Get them back out like this:

[[TMCache sharedCache] objectForKey:@"image"
                              block:^(TMCache *cache, NSString *key, id object) {
                                  UIImage *image = (UIImage *)object;
                                  NSLog(@"image scale: %f", image.scale);

TMMemoryCache allows for concurrent reads and serialized writes, while TMDiskCache serializes disk access across all instances in the app to increase performance and prevent file contention. TMCache coordinates them so that objects added to memory are available immediately to other threads while being written to disk safely in the background. Both caches are public properties of TMCache, so it's easy to manipulate one or the other separately if necessary.

Collections work too. Thanks to the magic of NSKeyedArchiver, objects repeated in a collection only occupy the space of one on disk:

NSArray *images = @[ image, image, image ];
[[TMCache sharedCache] setObject:images forKey:@"images"];
NSLog(@"3 for the price of 1: %d", [[[TMCache sharedCache] diskCache] byteCount]);



Download the latest tag and drag the TMCache folder into your Xcode project.

Install the docs by double clicking the .docset file under docs/, or view them online at

Git Submodule

git submodule add
git submodule update --init


Add TMCache to your Podfile and run pod install.


TMCache requires iOS 5.0 or OS X 10.7 and greater.


Please see for information on how to help out.


Bryan Irace


Copyright 2013 Tumblr, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.