Fix the issue when using thumbnailPixelSize and optionsProcessor

This commit is contained in:
DreamPiggy 2020-03-31 20:02:21 +08:00
parent d9fd4726ea
commit 94aadc1927
1 changed files with 14 additions and 12 deletions

View File

@ -106,18 +106,20 @@ public final class ImageManager : ObservableObject {
}
}
/// Prefetch the initial state of image
internal func prefetch() {
let key = manager.cacheKey(for: url)
if let imageCache = manager.imageCache as? SDImageCache {
self.image = imageCache.imageFromMemoryCache(forKey: key)
} else {
// generic API
manager.imageCache.containsImage(forKey: key, cacheType: .memory) { [unowned self] (cacheType) in
if cacheType == .memory {
self.manager.imageCache.queryImage(forKey: key, options: self.options, context: self.context) { [unowned self] (image, data, cacheType) in
self.image = image
}
/// Prefetch the initial state of image, currently query the memory cache only
func prefetch() {
// Use the options processor if provided
var context = self.context
if let result = manager.optionsProcessor?.processedResult(for: url, options: options, context: context) {
context = result.context
}
// TODO: before SDWebImage 5.7.0, this is the SPI. Remove later
let key = manager.perform(Selector(("cacheKeyForURL:context:")), with: url, with: context)?.takeUnretainedValue() as? String
// This callback is synchronzied
manager.imageCache.containsImage(forKey: key, cacheType: .memory) { [unowned self] (cacheType) in
if cacheType == .memory {
self.manager.imageCache.queryImage(forKey: key, options: self.options, context: self.context) { [unowned self] (image, data, cacheType) in
self.image = image
}
}
}