Kingfisher icon indicating copy to clipboard operation
Kingfisher copied to clipboard

Feature request: Make it possible to push only the original data to ImageCache

Open swftvsn opened this issue 7 years ago • 2 comments

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

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!

swftvsn avatar Sep 17 '18 18:09 swftvsn

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?

swftvsn avatar Sep 17 '18 18:09 swftvsn

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.

onevcat avatar Sep 18 '18 13:09 onevcat