Hello I am using the SDWebImage framework in a project and I want to download and cache images, but I think my code is storing an image in the cache twice? Is there any way
Yes is possible to download the image using SDWebImage And store into local memory Manually.
Downloaded Image store into local memory using SDWebImage
func saveImage(url: URL, toCache: UIImage?, complation: @escaping SDWebImageNoParamsBlock) {
guard let toCache = toCache else { return }
let manager = SDWebImageManager.shared()
if let key = manager.cacheKey(for: url) {
manager.imageCache?.store(toCache, forKey: key, completion: complation)
}
}
Load image from memory using image URL
static func imageFromMemory(for url: String) -> UIImage? {
if let encoded = url.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed),
let url = URL(string: encoded) {
let manager = SDWebImageManager.shared()
if let key: String = manager.cacheKey(for: url),
let image = manager.imageCache?.imageFromMemoryCache(forKey: key) {
return image
}
}
return nil
}