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

feat(image): [android] adding force-cache cache control option #47426

Conversation

mateoguzmana
Copy link
Contributor

Summary:

This PR follows up on #47182 and #47348 by adding force-cache, the final missing option to align caching controls with the existing behavior on iOS.

Local caching behavior remains unchanged: if a cached image is available locally, it will be returned; otherwise, a network request will be made.

When an image request is sent over the network, the force-cache option sent from the sent fJS side will now use the okhttp3.CacheControl.FORCE_CACHE directive.

Changelog:

[ANDROID] [ADDED] - Image force-cache caching control option

Test Plan:

New example added to the RNTester under the cache policy examples. Then inspecting that the cache control is set correctly before sending it in the okhttp3.Request builder.

FLog.w("ReactNative", "fetching uri: %s, with cacheControl: %s", uri, cacheControlBuilder.build().toString())
// fetching uri: https:...png?cacheBust=force-cache, with cacheControl: no-store, max-stale=2147483647, only-if-cached

This case was a bit more tricky to test in terms of e2e as it would involve some caching in the server as well, I'm open to suggestions to make this more complete.

@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 Nov 5, 2024
@mateoguzmana mateoguzmana marked this pull request as ready for review November 5, 2024 16:57
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 5, 2024
@facebook-github-bot
Copy link
Contributor

@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@Abbondanzo Abbondanzo left a comment

Choose a reason for hiding this comment

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

The cacheControlBuilder has noStore set, so none of the responses are getting cached.

  • Could you modify the builder to set noStore on the default and reload branches?
  • Could you update the only-if-cached branch to use the same max-age logic?

@mateoguzmana
Copy link
Contributor Author

@Abbondanzo thanks a lot again for taking the time to check these PRs! I've addressed all the feedback in dca3d3a

@facebook-github-bot
Copy link
Contributor

@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Nov 12, 2024
@facebook-github-bot
Copy link
Contributor

@Abbondanzo merged this pull request in a0be88f.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @mateoguzmana in a0be88f

When will my fix make it into a release? | How to file a pick request?

facebook-github-bot pushed a commit that referenced this pull request Dec 9, 2024
…ts (#47953)

Summary:
This is a follow up for the new cache control options for the Android Image component introduced in #47182, #47348 & #47426. And to make sure the cache control header works as expected and avoid missing the issue fixed in #47922, this PR introduces test cases to make sure this is getting applied as expected in the `ReactOkHttpNetworkFetcher`.

## Changelog:

[INTERNAL] [ADDED] - `ReactOkHttpNetworkFetcher` cache control tests

Pull Request resolved: #47953

Test Plan:
```bash
yarn test-android
```

Reviewed By: rshest

Differential Revision: D66498305

Pulled By: javache

fbshipit-source-id: 7a9a0cc596e49964943e59189614743ca8a472a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants