diff --git a/iOSClient/Media/NCMediaManager.swift b/iOSClient/Media/NCMediaManager.swift index 3a474f88cf..25213d93e7 100644 --- a/iOSClient/Media/NCMediaManager.swift +++ b/iOSClient/Media/NCMediaManager.swift @@ -10,15 +10,15 @@ import UIKit import LRUCache import NextcloudKit -class NCMediaManager { +@objc class NCMediaManager { - public static let shared: NCMediaManager = { + @objc public static let shared: NCMediaManager = { let instance = NCMediaManager() return instance }() - typealias ThumbnailLRUCache = LRUCache - let cache: ThumbnailLRUCache = ThumbnailLRUCache(countLimit: 2000) + private typealias ThumbnailLRUCache = LRUCache + private let cache: ThumbnailLRUCache = ThumbnailLRUCache(countLimit: 1500) func createCache(account: String) { @@ -39,6 +39,7 @@ class NCMediaManager { let startDate = Date() let startMemory = NCUtility.shared.getMemoryUsedAndDeviceTotalInMegabytes() NextcloudKit.shared.nkCommonInstance.writeLog("--------- start ThumbnailLRUCache image process ---------") + NextcloudKit.shared.nkCommonInstance.writeLog("Memory used in MB: \(startMemory.0)") // Get files only image / video if let enumerator = manager.enumerator(at: URL(fileURLWithPath: directory), includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles]) { @@ -58,8 +59,8 @@ class NCMediaManager { // Sort for most recent files.sort(by: { $0.date > $1.date }) if let firstDate = files.first?.date, let lastDate = files.last?.date { - NextcloudKit.shared.nkCommonInstance.writeLog("First date: \(firstDate)") - NextcloudKit.shared.nkCommonInstance.writeLog("Last date: \(lastDate)") + print("First date: \(firstDate)") + print("Last date: \(lastDate)") } // Insert in cache @@ -78,6 +79,7 @@ class NCMediaManager { let usedMemory = endMemory.0 - startMemory.0 NextcloudKit.shared.nkCommonInstance.writeLog("Counter process: \(cache.count)") NextcloudKit.shared.nkCommonInstance.writeLog("Time process: \(diffDate)") + NextcloudKit.shared.nkCommonInstance.writeLog("Memory used in MB: \(endMemory.0)") NextcloudKit.shared.nkCommonInstance.writeLog("Memory used for cache in MB: \(usedMemory)") NextcloudKit.shared.nkCommonInstance.writeLog("--------- stop ThumbnailLRUCache image process ---------") } @@ -91,4 +93,9 @@ class NCMediaManager { cache.setValue(image, forKey: ocId) } + + @objc func clearCache() { + + cache.removeAllValues() + } } diff --git a/iOSClient/Settings/CCAdvanced.m b/iOSClient/Settings/CCAdvanced.m index de5b1823cf..61ec16e0b8 100755 --- a/iOSClient/Settings/CCAdvanced.m +++ b/iOSClient/Settings/CCAdvanced.m @@ -386,6 +386,8 @@ - (void)clearCache:(NSString *)account [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self]; + [[NCMediaManager shared] clearCache]; + [[NCActivityIndicator shared] stop]; [self calculateSize]; });