iOS 通用缓存:HanekeSwift
Haneke 是个采用 Swift 编写的轻量级 iOS 通用缓存。示例:
初始化一个数据缓存:
let cache = Cache<NSData>("my-files")
Haneke 同时包括一个零配置的图片缓存,可以自动缩放。 示例:
imageView.hnk_setImageFromURL(url)
它的设计是超简单易用。这里是你如何初始化一个JSON缓存和从URL获取JSON对象:
let cache = Cache<JSON>("movies") let URL = NSURL(string: "http://haneke.io/movies.json") cache.fetch(URL: URL).onSuccess { JSON in // Do something with JSON }
特性
- Generic cache with out-of-the-box support for
UIImage
,NSData
,JSON
andString
- First-level memory cache using
NSCache
- Second-level LRU disk cache using the file system
- Asynchronous fetching of original values from network or disk
- All disk access is performed in background
- Thread-safe
- Automatic cache eviction on memory warnings or disk capacity reached
- Comprehensive unit tests
- Extensible by defining custom formats, supporting additional types or implementing custom fetchers
项目主页:http://www.open-open.com/lib/view/home/1412904232717
时间: 2024-10-02 11:47:07