Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Custom cache key on af_setImage #222

Closed
lingzlu opened this issue Dec 8, 2016 · 4 comments
Closed

Custom cache key on af_setImage #222

lingzlu opened this issue Dec 8, 2016 · 4 comments

Comments

@lingzlu
Copy link

lingzlu commented Dec 8, 2016

We have an image URL that's unique generated every time we call an end point, the URL is short living and expires in about 10 mins. When I use the af_setImage function, the default identifier is generated base on the request.absoluteURL, which does not work well in this case. I'm looking at KIngfisher library where they have option to set the custom cache key like

let resource = ImageResource(downloadURL:imageURL, cacheKey: customKey)
imageView.kf.setImage(with: resource ....

I would think AlamofireImage can do something similar by replacing the urlRequest parameter with a resource object that wraps around download url and cache key?

@cybercent
Copy link

Workaround:
Instead of doing a GET request to fetch the image, do a POST request.
Remove the short-lived params from the query string and pass them as POST params.
Use af_setImage(withURLRequest: ..) instead of af_setImage(withURL: ..).
Your URL with not change and the cache will work.

@jshier
Copy link
Contributor

jshier commented Jan 2, 2017

@cnoon, we support this at the cache level (appending an additional identifier), seems like we could just plumb it through to the UIImageView extension? However, that API is getting rather out of hand. Perhaps something of a refactor would be advised?

@cnoon
Copy link
Member

cnoon commented Feb 27, 2017

Yep, agreed @jshier. We could certainly append the key for now and then rethink these APIs in the next major release. I'll see what I can put together here.

@cnoon
Copy link
Member

cnoon commented Feb 27, 2017

I just spoke with @jshier about the complexity here and it's a bit too involved to do properly in the AFI 3.x APIs. We've put together a fairly detailed card into our Trello backlog to pick this up when we start on the AFI4 changes. I'm going to close this issue out for now and link it to that milestone. We'll re-open once we get closer to starting that work.

Cheers. 🍻

@cnoon cnoon closed this as completed Feb 27, 2017
@cnoon cnoon added this to the 4.0.0 milestone Feb 27, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants