override func didReceiveMemoryWarning() {
PIImageCache.shared.allMemoryCacheDelete()
}
func applicationDidEnterBackground(application: UIApplication) {
PIImageCache.shared.oldDiskCacheDelete()
}
let url = NSURL(string: "http://place-hold.it/200x200")!
let image = url.getImageWithCache()
let url = NSURL(string: "http://place-hold.it/200x200")!
let imgView = UIImageView()
imgView.imageOfURL(url)
let url = NSURL(string: "http://place-hold.it/200x200")!
let cache = PIImageCache.shared
image = cache.get(url)!
let url = NSURL(string: "http://place-hold.it/200x200")!
let cache = PIImageCache.shared
cache.prefetch(url)
设置 id,使用 id 获取回调图像。
这对 UITableViewCell 很有用。
// example: code in cellForRowAtIndexPath
let url = NSURL(string: "http://lorempixel.com/200/200/" )!
let id = indexPath.row
cell.id = indexPath.row
PIImageCache.shared.getWithId(url, id: i) {
[weak self] id, image in
if id == cell.id {
cell.icon.image = image
}
}
let cache = PIImageCache.shared
var config = PIImageCache.Config()
config.maxMemorySum = 5
config.limitByteSize = 100 * 1024 // 100kB
cache.setConfig(config)
let url = NSURL(string: "http://place-hold.it/200x200")!
let image = cache.get(url)!