Fast, thread-safe memory and disk object cache for Apple platforms
open sourceApache-2.0free
Forked from TMCache. Re-architected to fix issues with deadlocking caused by heavy use
PINCache is Pinterest's key/value object cache for iOS, macOS, tvOS and watchOS, for keeping temporary objects that are expensive to make again, such as downloaded data or the results of slow processing. It pairs an in-memory store (PINMemoryCache) with an on-disk one (PINDiskCache), both backed by GCD and safe to use from several threads at once: objects added to memory are available to other threads at once while they're written to disk in the background. The memory cache clears itself on a memory warning or when the app goes into the background, and the disk cache keeps objects until you trim it by hand or with a byte or age limit. It stores any NSCoding object. Pinterest forked it from Tumblr's TMCache and re-architected it to fix deadlocks under heavy use.
Problems it solves
- cache downloaded images in my iOS app across launches
- keep expensive objects in memory and on disk without deadlocks in Swift
- an iOS object cache that empties itself on a memory warning
Features
- paired memory and disk caches, safe from several threads
- memory cache clears on memory warnings and backgrounding
- disk cache trimmed by byte or age limits
- stores any NSCoding object, from Objective-C or Swift
