A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 阿泽泽 中级黑马   /  2016-5-14 00:28  /  662 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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 and String
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

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马