forked from shadowfacts/Tusker
Minimize file system requests during image cache lookup
This commit is contained in:
parent
3822d536c8
commit
3e33c8e6f9
|
@ -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):
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue