Add kingfisher delete disk cache

This commit is contained in:
kevinzhow
2015-11-01 05:22:20 +08:00
parent bb1308f0b4
commit bbcd4beddb
2 changed files with 39 additions and 0 deletions
+27
View File
@@ -10,6 +10,8 @@ import Foundation
import RealmSwift
import Navi
typealias CancelableTask = (cancel: Bool) -> Void
extension String {
@@ -87,3 +89,28 @@ func isOperatingSystemAtLeastMajorVersion(majorVersion: Int) -> Bool {
return NSProcessInfo().isOperatingSystemAtLeastVersion(NSOperatingSystemVersion(majorVersion: majorVersion, minorVersion: 0, patchVersion: 0))
}
extension String {
func stringByAppendingPathComponent(path: String) -> String {
return (self as NSString).stringByAppendingPathComponent(path)
}
}
func cleanDiskCacheFolder() {
let folderPath = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0]
let fileMgr = NSFileManager.defaultManager()
guard let fileArray = try? fileMgr.contentsOfDirectoryAtPath(folderPath) else {
return
}
for filename in fileArray {
do {
try fileMgr.removeItemAtPath(folderPath.stringByAppendingPathComponent(filename))
} catch {
print(" clean error ")
}
}
}
@@ -12,6 +12,7 @@ import MonkeyKing
import Navi
import Crashlytics
import SafariServices
import Kingfisher
let profileAvatarAspectRatio: CGFloat = 12.0 / 16.0
@@ -499,6 +500,17 @@ class ProfileViewController: UIViewController {
syncMyInfoAndDoFurtherAction {
}
Kingfisher.ImageCache(name: "default").calculateDiskCacheSizeWithCompletionHandler({ (size) -> () in
let cacheSize = Double(size)/1000000
println(String(format: "%.2f MB", cacheSize))
if cacheSize > 300 {
Kingfisher.ImageCache.defaultCache.clearDiskCache()
}
})
title = NSLocalizedString("Profile", comment: "")