Minimize file system requests during image cache lookup

This commit is contained in:
Shadowfacts 2020-09-17 19:50:53 -04:00
parent 3822d536c8
commit 3e33c8e6f9
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 2 additions and 2 deletions

View File

@ -15,6 +15,7 @@ enum Cache<T> {
case disk(DiskStorage<T>)
case hybrid(HybridStorage<T>)
@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):

View File

@ -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 {