-
Notifications
You must be signed in to change notification settings - Fork 522
Custom Cache Key for images #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cnoon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together @graphiclife! 🍻
Just a few minor changes before we push this through.
| _ urlRequest: URLRequestConvertible, | ||
| receiptID: String = UUID().uuidString, | ||
| filter: ImageFilter? = nil, | ||
| customCacheKey: String? = nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a docstring for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Source/ImageDownloader.swift
Outdated
| switch request.cachePolicy { | ||
| case .useProtocolCachePolicy, .returnCacheDataElseLoad, .returnCacheDataDontLoad: | ||
| if let image = self.imageCache?.image(for: request, withIdentifier: filter?.identifier) { | ||
| var cachedImage: Image? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a let?
| strongSelf.imageCache?.add(filteredImage, withIdentifier: customCacheKey) | ||
| } else { | ||
| strongSelf.imageCache?.add(filteredImage, for: request, withIdentifier: filter?.identifier) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌🏻
| url: URL, | ||
| placeholderImage: UIImage? = nil, | ||
| filter: ImageFilter? = nil, | ||
| customCacheKey: String? = nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring?
| progressQueue: DispatchQueue = DispatchQueue.main, | ||
| imageTransition: ImageTransition = .noTransition, | ||
| runImageTransitionIfCached: Bool = false, | ||
| customCacheKey: String? = nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring?
|
Apologies for not getting back to you sooner about this PR @graphiclife. I like this approach better than #328. I'm going to close that one out in favor of this approach. |
Added parameter customCacheKey in af_setImage in UIImageView+AlamofireImage, UIButton+AlamofireImage. Added parameter customCacheKey in ImageDownloader.download Added test testThatImageCanBeCachedWithACustomCacheKey * Added docstring for customCacheKey. * 'var' -> 'let' for cachedImage
|
@cnoon Any updates on this? |
|
Not yet @graphiclife, right now we're very focused on the AF5 release and keeping AFI in sync with that. I'm not sure right now if this change will make it into AFI 4 or not. |
|
Hi guys, just wondering, do you have a timeline to get into master? I am having the same issue, and this approach would suffice. Is there anything I or someone could do to bring this to master? |
|
Hi @graphiclife, I have squashed these changes with a few edits and added tests in deff207 and pushed the change into Cheers. 🍻 |
|
@cnoon Excellent news, thanks! |
Added parameter customCacheKey in af_setImage in UIImageView+AlamofireImage, UIButton+AlamofireImage.
Added parameter customCacheKey in ImageDownloader.download
Added test testThatImageCanBeCachedWithACustomCacheKey
Goals ⚽
Ability to cache images based on other factors than the url, which could be necessary if the backend hosting the image has a misconfigured cache management or provides images through REST-endpoints.
Implementation Details 🚧
Added an optional cache key parameter to af_setImage-functions.
Testing Details 🔍
Added testThatImageCanBeCachedWithACustomCacheKey in UIImageViewTests .