From 3e33c8e6f9320d64649692d70dbebc618df0588d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 17 Sep 2020 19:50:53 -0400 Subject: [PATCH] Minimize file system requests during image cache lookup --- Tusker/Caching/Cache.swift | 1 + Tusker/Caching/ImageCache.swift | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tusker/Caching/Cache.swift b/Tusker/Caching/Cache.swift index efa0c02c..5a38e9e8 100644 --- a/Tusker/Caching/Cache.swift +++ b/Tusker/Caching/Cache.swift @@ -15,6 +15,7 @@ enum Cache { case disk(DiskStorage) case hybrid(HybridStorage) + @available(*, deprecated, message: "disk-based caches synchronously interact with the file system. Avoid using if possible.") func existsObject(forKey key: String) throws -> Bool { switch self { case let .memory(memory): diff --git a/Tusker/Caching/ImageCache.swift b/Tusker/Caching/ImageCache.swift index fcd4052c..792fda47 100644 --- a/Tusker/Caching/ImageCache.swift +++ b/Tusker/Caching/ImageCache.swift @@ -38,8 +38,7 @@ class ImageCache { func get(_ url: URL, completion: ((Data?) -> Void)?) -> Request? { let key = url.absoluteString - if (try? cache.existsObject(forKey: key)) ?? false, - let data = try? cache.object(forKey: key) { + if let data = try? cache.object(forKey: key) { completion?(data) return nil } else {