@@ -116,15 +116,30 @@ public final class ImageManager : ObservableObject {
116116 if let result = manager. optionsProcessor? . processedResult ( for: url, options: options, context: context) {
117117 context = result. context
118118 }
119+ // TODO: Remove transformer for cache calculation before SDWebImage 5.7.0, this is bug. Remove later
120+ let transformer = ( context ? [ . imageTransformer] as? SDImageTransformer ) ?? manager. transformer
121+ context ? [ . imageTransformer] = nil
119122 // TODO: before SDWebImage 5.7.0, this is the SPI. Remove later
120- let key = manager. perform ( Selector ( ( " cacheKeyForURL:context: " ) ) , with: url, with: context) ? . takeUnretainedValue ( ) as? String
121- // This callback is synchronzied
122- manager. imageCache. containsImage ( forKey: key, cacheType: . memory) { [ unowned self] ( cacheType) in
123- if cacheType == . memory {
124- self . manager. imageCache. queryImage ( forKey: key, options: options, context: context) { [ unowned self] ( image, data, cacheType) in
125- self . image = image
126- if let image = image {
127- self . successBlock ? ( image, cacheType)
123+ var key = manager. perform ( Selector ( ( " cacheKeyForURL:context: " ) ) , with: url, with: context) ? . takeUnretainedValue ( ) as? String
124+ if let transformer = transformer {
125+ key = SDTransformedKeyForKey ( key, transformer. transformerKey)
126+ }
127+ // Shortcut for built-in cache
128+ if let imageCache = manager. imageCache as? SDImageCache {
129+ let image = imageCache. imageFromMemoryCache ( forKey: key)
130+ self . image = image
131+ if let image = image {
132+ self . successBlock ? ( image, . memory)
133+ }
134+ } else {
135+ // This callback is synchronzied
136+ manager. imageCache. containsImage ( forKey: key, cacheType: . memory) { [ unowned self] ( cacheType) in
137+ if cacheType == . memory {
138+ self . manager. imageCache. queryImage ( forKey: key, options: options, context: context) { [ unowned self] ( image, data, cacheType) in
139+ self . image = image
140+ if let image = image {
141+ self . successBlock ? ( image, cacheType)
142+ }
128143 }
129144 }
130145 }
0 commit comments