Feature request: Make it possible to push only the original data to ImageCache
Check List
Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.
- [ X ] I have read the wiki page and cheat sheet, but there is no information I need.
- [ X ] I have searched in existing issues, but did not find a same one.
- [ X ] I want to report a problem instead of asking a question. It'd better to use kingfisher tag in Stack Overflow to ask a question.
Issue Description
It's a bit hard to save data to cache. That is, I receive data from subsystem, but don't have any associated UIImage available. This forces me to create uiimage for no purpose.
What
It would be nice to be able to do this:
func cacheData(url: String, data: Data) {
ImageCache.default.storeOriginal(data, forKey: url)
}
And then just let Kingfisher load the image, it would find out that there is no image yet for the processors, but it seems that original image data can be found.
If I have missed a way to do this, please advice? Any workarounds are also greatly appreciated!
Now that I have read a bit more code, maybe I should just do
let image = DefaultCacheSerializer.default.image(with: data: options: nil)
ImageCache.default.store(image, original: data, forKey: url)
and be happy :)
Can anyone confirm, that the code above is good to save original picture?
Yes, you are right. A method for storing raw data only would be useful. I think I would add it later.
For now, the code snippet you posted should work perfectly, except that it creates and cache the image object in memory even you do not need it yet.