Skip to content

Commit 94aadc1

Browse files
committed
Fix the issue when using thumbnailPixelSize and optionsProcessor
1 parent d9fd472 commit 94aadc1

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

SDWebImageSwiftUI/Classes/ImageManager.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,20 @@ public final class ImageManager : ObservableObject {
106106
}
107107
}
108108

109-
/// Prefetch the initial state of image
110-
internal func prefetch() {
111-
let key = manager.cacheKey(for: url)
112-
if let imageCache = manager.imageCache as? SDImageCache {
113-
self.image = imageCache.imageFromMemoryCache(forKey: key)
114-
} else {
115-
// generic API
116-
manager.imageCache.containsImage(forKey: key, cacheType: .memory) { [unowned self] (cacheType) in
117-
if cacheType == .memory {
118-
self.manager.imageCache.queryImage(forKey: key, options: self.options, context: self.context) { [unowned self] (image, data, cacheType) in
119-
self.image = image
120-
}
109+
/// Prefetch the initial state of image, currently query the memory cache only
110+
func prefetch() {
111+
// Use the options processor if provided
112+
var context = self.context
113+
if let result = manager.optionsProcessor?.processedResult(for: url, options: options, context: context) {
114+
context = result.context
115+
}
116+
// TODO: before SDWebImage 5.7.0, this is the SPI. Remove later
117+
let key = manager.perform(Selector(("cacheKeyForURL:context:")), with: url, with: context)?.takeUnretainedValue() as? String
118+
// This callback is synchronzied
119+
manager.imageCache.containsImage(forKey: key, cacheType: .memory) { [unowned self] (cacheType) in
120+
if cacheType == .memory {
121+
self.manager.imageCache.queryImage(forKey: key, options: self.options, context: self.context) { [unowned self] (image, data, cacheType) in
122+
self.image = image
121123
}
122124
}
123125
}

0 commit comments

Comments
 (0)