Created
November 3, 2019 18:16
-
-
Save sgl0v/3f5cf1ff76d1cf00b859c0da315d9967 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension ImageCache: ImageCacheType { | |
| func insertImage(_ image: UIImage?, for url: URL) { | |
| guard let image = image else { return removeImage(for: url) } | |
| let decodedImage = image.decodedImage() | |
| lock.lock(); defer { lock.unlock() } | |
| imageCache.setObject(decodedImage, forKey: url as AnyObject) | |
| decodedImageCache.setObject(image as AnyObject, forKey: url as AnyObject, cost: decodedImage.diskSize) | |
| } | |
| func removeImage(for url: URL) { | |
| lock.lock(); defer { lock.unlock() } | |
| imageCache.removeObject(forKey: url as AnyObject) | |
| decodedImageCache.removeObject(forKey: url as AnyObject) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I was reading Reusable Image Cache in Swift
This code is adding the decoded image to the encoded cache and vise versa.
Also, you don't say what 'diskSize' is: presumably another convenience extension?
Other than that LGTM 👍