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

[iOS] Enhance image freshness check before stored into cache #23226

Closed

Conversation

zhongwuzw
Copy link
Contributor

@zhongwuzw zhongwuzw commented Jan 31, 2019

Summary

Currently, before we store the image to cache, we only respect Cache-Control, actually, we also may need to check ExpiresLast-Modified, refer to MDN docs, and okhttp respect the MDN, so in iOS, we can also respect this.

Changelog

[iOS] [Fixed] - Respect MDN cache strategy before cache the image.

Test Plan

After PR, if image's response do not contains Cache-Control, it would also checks ExpiresLast-Modified refers to MDN docs.

@zhongwuzw zhongwuzw requested a review from shergin as a code owner January 31, 2019 07:02
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 31, 2019
@@ -31,8 +31,7 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
size:(CGSize)size
scale:(CGFloat)scale
resizeMode:(RCTResizeMode)resizeMode
responseDate:(NSString *)responseDate
cacheControl:(NSString *)cacheControl;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only pass responseDate or cacheControl may not sufficient, we can just pass response that we can get any response header we want.

Copy link
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

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

Thanks for adding this functionality. Passing the response directly seems like the right choice as it simplifies the callsites.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jan 31, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

@zhongwuzw merged commit e98d5a2 into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Jan 31, 2019
@react-native-bot react-native-bot added the Merged This PR has been merged. label Jan 31, 2019
@cpojer
Copy link
Contributor

cpojer commented Feb 6, 2019

Just landed this one again in fb8ba3f

@hramos hramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 6, 2019
matt-oakes pushed a commit to matt-oakes/react-native that referenced this pull request Feb 7, 2019
Summary:
Currently, before we store the image to cache, we only respect `Cache-Control`, actually, we also may need to check `Expires`、`Last-Modified`, refer to [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching#Freshness), and  [okhttp](https://github.com/square/okhttp/blob/568a91c44a118b2c2ba62d310a331582c567b24a/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.java#L268) respect the `MDN`, so in iOS, we can also respect this.

[iOS] [Fixed] - Respect `MDN` cache strategy before cache the image.

After `PR`, if image's response do not contains `Cache-Control`, it would also checks `Expires`、`Last-Modified` refers to  [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching#Freshness).
Pull Request resolved: facebook#23226

Differential Revision: D13895627

Pulled By: cpojer

fbshipit-source-id: aa377511c31badd752d7887ed6cbcdf6be4b80b3
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Component: Image Merged This PR has been merged. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants