-
-
Save laevandus/eeff3cc5331c65163c06cee5caec8698 to your computer and use it in GitHub Desktop.
This file contains 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
struct AsyncPhotoCache: AsyncPhotoCaching { | |
private var storage: NSCache<NSString, UIImage> | |
static let shared = AsyncPhotoCache(countLimit: 10) | |
init(countLimit: Int) { | |
self.storage = NSCache() | |
self.storage.countLimit = countLimit | |
} | |
func store(_ image: UIImage, forID id: any Hashable) { | |
let key = cacheKey(for: id, size: image.size) | |
storage.setObject(image, forKey: key as NSString) | |
} | |
func image(for id: any Hashable, size: CGSize) -> UIImage? { | |
let key = cacheKey(for: id, size: size) | |
return storage.object(forKey: key as NSString) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment