mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-11 05:45:56 +10:00
Add kingfisher delete disk cache
This commit is contained in:
@@ -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: "")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user