瀏覽代碼

improvements

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 年之前
父節點
當前提交
6a560e3d80
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      iOSClient/Media/NCMediaCache.swift

+ 7 - 1
iOSClient/Media/NCMediaCache.swift

@@ -32,8 +32,11 @@ import NextcloudKit
         return instance
     }()
 
+    let limit: Int = 2000
     private typealias ThumbnailLRUCache = LRUCache<String, UIImage>
-    private let cache: ThumbnailLRUCache = ThumbnailLRUCache(countLimit: 2000)
+    private lazy var cache: ThumbnailLRUCache = {
+        return ThumbnailLRUCache(countLimit: limit)
+    }()
 
     func createCache(account: String) {
 
@@ -76,7 +79,10 @@ import NextcloudKit
 
         // Insert in cache
         cache.removeAllValues()
+        var counter: Int = 0
         for file in files {
+            counter += 1
+            if counter > limit { break }
             autoreleasepool {
                 if let image = UIImage(contentsOfFile: file.path.path) {
                     cache.setValue(image, forKey: file.ocId)