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 disk(DiskStorage<T>)
|
||||||
case hybrid(HybridStorage<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 {
|
func existsObject(forKey key: String) throws -> Bool {
|
||||||
switch self {
|
switch self {
|
||||||
case let .memory(memory):
|
case let .memory(memory):
|
||||||
|
|
|
@ -38,8 +38,7 @@ class ImageCache {
|
||||||
|
|
||||||
func get(_ url: URL, completion: ((Data?) -> Void)?) -> Request? {
|
func get(_ url: URL, completion: ((Data?) -> Void)?) -> Request? {
|
||||||
let key = url.absoluteString
|
let key = url.absoluteString
|
||||||
if (try? cache.existsObject(forKey: key)) ?? false,
|
if let data = try? cache.object(forKey: key) {
|
||||||
let data = try? cache.object(forKey: key) {
|
|
||||||
completion?(data)
|
completion?(data)
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue