YYCache

High performance cache framework for iOS.

(It's a component of YYKit)

Performance

Memory cache benchmark result

Disk benchmark result

You may download and compile the latest version of sqlite and ignore the libsqlite3.dylib in iOS system to get higher performance.

See Benchmark/CacheBenchmark.xcodeproj for more benchmark case.

Features

  • LRU: Objects can be evicted with least-recently-used algorithm.
  • Limitation: Cache limitation can be controlled with count, cost, age and free space.
  • Compatibility: The API is similar to NSCache, all methods are thread-safe.
  • Memory Cache
    • Release Control: Objects can be released synchronously/asynchronously on main thread or background thread.
    • Automatically Clear: It can be configured to automatically evict objects when receive memory warning or app enter background.
  • Disk Cache
    • Customization: It supports custom archive and unarchive method to store object which does not adopt NSCoding.
    • Storage Type Control: It can automatically decide the storage type (sqlite / file) for each object to get
      better performance.

Installation

CocoaPods

  1. Add pod 'YYCache' to your Podfile.
  2. Run pod install or pod update.
  3. Import <YYCache/YYCache.h>.

Carthage

  1. Add github "ibireme/YYCache" to your Cartfile.
  2. Run carthage update --platform ios and add the framework to your project.
  3. Import <YYCache/YYCache.h>.

Manually

  1. Download all the files in the YYCache subdirectory.
  2. Add the source files to your Xcode project.
  3. Link with required frameworks:
    • UIKit
    • CoreFoundation
    • QuartzCore
    • sqlite3
  4. Import YYCache.h.

Documentation

Full API documentation is available on CocoaDocs.

You can also install documentation locally using appledoc.

Requirements

This library requires iOS 6.0+ and Xcode 8.0+.

GitHub