Skip to content
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

Refactory the current thumbnail && transformer about cache key. Developer should have the API to calcualte the cache key from thumbnail or transformer, not hard-coded. #2966

Merged

Conversation

dreampiggy
Copy link
Contributor

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found none

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

This merge request fixes / refers to the following issues: ...

Pull Request Description

Motivation

Current Thumbnail (introduced in 5.6.0) and Transformer with cache key is not works correct. For example:

  1. The thumbnail's cache key does not applied when you have a transformer at the same time...Only the transformer key get applied. Bug...
  2. The transformer's cache key and thumbnail cache key is hard to generate, which means most of cache API (imageFromMemoryForKey:) need to care about and generate cache key manually
  3. The thumbnail's cache key (That harded "Thumbnail({%f,%f},%d)) does not have any public way to access this unless you harcode. Which means, you can not directly get the thumbnail image from cache by yourself without SDWebImageManager.

Changes

New API:

  • SDThumbnailedKeyForKey()

Used for public API to generate thumbnail cache key, if you access the cache directly without SDWebImageManager.

+cacheKeyForURL:context:

Used for user who don't want to care about what context in it (it may have thumbnail pixel size, it may have cache filter, it may have transformer...etc). Just pass in the context, we give you the final cache key which can directly passed to SDImageCache

@return The transformed image, or nil if transform failed
*/
- (nullable UIImage *)transformedImageWithImage:(nonnull UIImage *)image forKey:(nonnull NSString *)key;
- (nullable UIImage *)transformedImageWithImage:(nonnull UIImage *)image forKey:(nonnull NSString *)key API_DEPRECATED("The key arg will be removed in the future. Update your code and don't rely on that.", macos(10.10, API_TO_BE_DEPRECATED), ios(8.0, API_TO_BE_DEPRECATED), tvos(9.0, API_TO_BE_DEPRECATED), watchos(2.0, API_TO_BE_DEPRECATED));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the method signature to nullable for this key arg ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okey to change in nullable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems change it to nullable will cause API break for exist custom protocol for Swift User. (Objective-C does not cause issue). So let keep it until 6.0.0

@dreampiggy dreampiggy added this to the 5.7.0 milestone Mar 31, 2020
@kinarobin
Copy link
Member

Could you update some test case?

@dreampiggy dreampiggy force-pushed the bugfix_refactory_thumbnail_cache_key branch 2 times, most recently from 3d7ddae to 499540c Compare April 1, 2020 04:10
@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

Merging #2966 into master will decrease coverage by 0.12%.
The diff coverage is 77.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2966      +/-   ##
==========================================
- Coverage   83.83%   83.71%   -0.13%     
==========================================
  Files          69       69              
  Lines        7286     7312      +26     
==========================================
+ Hits         6108     6121      +13     
- Misses       1178     1191      +13     
Flag Coverage Δ
#ios 83.65% <77.50%> (-0.37%) ⬇️
#macos 83.55% <77.50%> (-0.16%) ⬇️
#tvos 83.66% <77.50%> (-0.38%) ⬇️
Impacted Files Coverage Δ
SDWebImage/Core/SDImageTransformer.m 87.69% <0.00%> (-2.08%) ⬇️
SDWebImage/Core/SDImageCache.m 77.79% <57.14%> (-1.31%) ⬇️
SDWebImage/Core/SDWebImageManager.m 90.27% <90.00%> (-0.22%) ⬇️
SDWebImage/Core/SDWebImageDownloader.m 85.90% <0.00%> (-0.55%) ⬇️
SDWebImage/Core/SDWebImageDownloaderOperation.m 92.33% <0.00%> (-0.30%) ⬇️
SDWebImage/Core/SDAnimatedImagePlayer.m 89.16% <0.00%> (+0.41%) ⬆️
SDWebImage/Core/SDWebImagePrefetcher.m 91.19% <0.00%> (+1.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51dee05...8c2141e. Read the comment docs.

@dreampiggy dreampiggy force-pushed the bugfix_refactory_thumbnail_cache_key branch 2 times, most recently from 93b665c to fac9535 Compare April 1, 2020 09:30
@dreampiggy dreampiggy force-pushed the bugfix_refactory_thumbnail_cache_key branch from fac9535 to b766c58 Compare April 2, 2020 12:16
@@ -227,7 +227,7 @@ typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) {
#pragma mark - Query and Retrieve Ops

/**
* Asynchronously queries the cache with operation and call the completion when done.
* Synchronously queries the cache with operation and call the completion when done.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation needs update...

…eeded if you have animated image/transformer/thumbnail usage
@dreampiggy dreampiggy force-pushed the bugfix_refactory_thumbnail_cache_key branch from b766c58 to 8c2141e Compare April 3, 2020 03:26
@dreampiggy dreampiggy merged commit 897e38c into SDWebImage:master Apr 3, 2020
@dreampiggy dreampiggy deleted the bugfix_refactory_thumbnail_cache_key branch April 3, 2020 08:31
@dreampiggy dreampiggy mentioned this pull request Jun 22, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants