Tarvo Mäesepp Tarvo Mäesepp - 3 months ago 58
Swift Question

Images not caching with Firebase url but caching with other

I have little problem. I got caching to work with the following

URL
:

let URL = NSURL(string: "https://raw.githubusercontent.com/onevcat/Kingfisher/master/images/kingfisher-\(indexPath.row + 1).jpg")!


But can't get it to work like this with this
URL
:

FIRStorage.storage().reference().child("\(productImageref!).png").downloadURLWithCompletion({(url, error)in

if error != nil{
print(error)
return
}else{

cell.snusProductImageView.kf_setImageWithURL(url , placeholderImage: nil,
optionsInfo: [.Transition(ImageTransition.Fade(1))],
progressBlock: { receivedSize, totalSize in
print("\(indexPath.row + 1): \(receivedSize)/\(totalSize)")
},
completionHandler: { image, error, cacheType, imageURL in
print("\(indexPath.row + 1): Finished")

})
}
})


What I am doing wrong here? Can you point me to the right direction? For caching I use the 3rd party library "KingFisher"

Edit: Firebase guy Mike McDonald's quote


"The Github one has Cache-Control: max-age=300 while Firebase Storage
doesn't have cache control set by default (you can set it when you
upload the file, or change it by updating metadata), so I assume
that's why KingFisher isn't caching it."


KingFisher owner quotes.

Answer

The way I got them caching was that I had to write all image url-s into JSON like this:

.setValue(url!.absoluteString)

And then read those as url-s

Comments