Kaynağa Gözat

Remove sync disk cache clear

All disk cache clear should happen in ioQueue.
onevcat 10 yıl önce
ebeveyn
işleme
ab8fadf212

+ 8 - 17
Kingfisher/ImageCache.swift

@@ -361,15 +361,9 @@ extension ImageCache {
     /**
     Clear disk cache. This is could be an async or sync operation.
     Specify the way you want it by passing the `sync` parameter.
-     
-    - parameter sync: If `true`, the clear process will be performed in a sync way. Otherwise, async. Default is `false`.
     */
-    public func clearDiskCache(sync: Bool = false) {
-        if sync {
-            clearDiskCacheSync()
-        } else {
-            clearDiskCacheWithCompletionHandler(nil)
-        }
+    public func clearDiskCache() {
+        clearDiskCacheWithCompletionHandler(nil)
     }
     
     /**
@@ -379,7 +373,12 @@ extension ImageCache {
     */
     public func clearDiskCacheWithCompletionHandler(completionHander: (()->())?) {
         dispatch_async(ioQueue, { () -> Void in
-            self.clearDiskCacheSync()
+            do {
+                try self.fileManager.removeItemAtPath(self.diskCachePath)
+                try self.fileManager.createDirectoryAtPath(self.diskCachePath, withIntermediateDirectories: true, attributes: nil)
+            } catch _ {
+            }
+            
             if let completionHander = completionHander {
                 dispatch_async(dispatch_get_main_queue(), { () -> Void in
                     completionHander()
@@ -388,14 +387,6 @@ extension ImageCache {
         })
     }
     
-    func clearDiskCacheSync() {
-        do {
-            try self.fileManager.removeItemAtPath(self.diskCachePath)
-            try self.fileManager.createDirectoryAtPath(self.diskCachePath, withIntermediateDirectories: true, attributes: nil)
-        } catch _ {
-        }
-    }
-    
     /**
     Clean expired disk cache. This is an async operation.
     */

+ 1 - 1
KingfisherTests/KingfisherTestHelper.swift

@@ -50,6 +50,6 @@ func cleanDefaultCache() {
 func clearCaches(caches: [ImageCache]) {
     for c in caches {
         c.clearMemoryCache()
-        c.clearDiskCache(true)
+        c.clearDiskCache()
     }
 }

+ 2 - 2
KingfisherTests/UIImageViewExtensionTests.swift

@@ -321,8 +321,8 @@ class UIImageViewExtensionTests: XCTestCase {
         let cache1 = ImageCache(name: "cache1")
         let cache2 = ImageCache(name: "cache2")
         
-        cache1.clearDiskCache(true)
-        cache2.clearDiskCache(true)
+        cache1.clearDiskCache()
+        cache2.clearDiskCache()
         
         let expectation = expectationWithDescription("wait for downloading image")