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

enhancement: Set URLRequest cache policy on GET requests #476

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

calvincestari
Copy link
Member

@calvincestari calvincestari commented Sep 11, 2024

Closes apollographql/apollo-ios#3432.

There is currently no way for a user to opt-out of the URLRequest default caching behaviour. This PR simply sets a comparable cache policy on URLRequest for GET requests.

  • returnCacheDataElseFetch == returnCacheDataElseLoad: Direct comparison
  • fetchIgnoringCacheData == reloadIgnoringLocalCacheData: The Apollo iOS version of this cache policy means that only the request will ignore cached data but the response will still be cached. It seems correct to ignore any iOS cached responses but still use any remote (CDN) cached responses.
  • fetchIgnoringCacheCompletely == reloadIgnoringLocalAndRemoteCacheData: The Apollo iOS version of this cache policy will ignore cached data for the request but it will also not cache any response data. The equivalent URLRequest policy here is to ignore all local (iOS) and remote (CDN) cached data and always go to the server for a response.
  • returnCacheDataDontFetch == returnCacheDataDontLoad: Direct comparison
  • returnCacheDataAndFetch == reloadRevalidatingCacheData: The Apollo iOS request chain will handle the return-cache-data portion of this policy but we extend that to any iOS cached responses, for and-fetch, by making iOS ensure any cached responses are still valid, otherwise fetch from the server.

Copy link

netlify bot commented Sep 11, 2024

Deploy Preview for eclectic-pie-88a2ba canceled.

Name Link
🔨 Latest commit 511b76a
🔍 Latest deploy log https://app.netlify.com/sites/eclectic-pie-88a2ba/deploys/66e0e22600c275000859bf32

Copy link

netlify bot commented Sep 11, 2024

Deploy Preview for apollo-ios-docc canceled.

Name Link
🔨 Latest commit 511b76a
🔍 Latest deploy log https://app.netlify.com/sites/apollo-ios-docc/deploys/66e0e226f60d6f000871cd4b

@calvincestari calvincestari marked this pull request as ready for review September 11, 2024 00:29
Copy link
Member

@BobaFetters BobaFetters left a comment

Choose a reason for hiding this comment

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

This LGTM, think the mappings of the cache policies makes sense

@calvincestari
Copy link
Member Author

This LGTM, think the mappings of the cache policies makes sense

The only question I have is whether the following should ignore remote caches or not?

  • fetchIgnoringCacheData == reloadIgnoringLocalCacheData: The Apollo iOS version of this cache policy means that only the request will ignore cached data but the response will still be cached. It seems correct to ignore any iOS cached responses but still use any remote (CDN) cached responses.

@BobaFetters
Copy link
Member

The only question I have is whether the following should ignore remote caches or not?

  • fetchIgnoringCacheData == reloadIgnoringLocalCacheData: The Apollo iOS version of this cache policy means that only the request will ignore cached data but the response will still be cached. It seems correct to ignore any iOS cached responses but still use any remote (CDN) cached responses.

Yea I think thats a reasonable assumption that it should ignore anything cached on the iOS client side which is what Apollo iOS would be doing, but could still use remote cached responses.

Copy link
Contributor

@AnthonyMDev AnthonyMDev left a comment

Choose a reason for hiding this comment

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

Thanks Calvin!

@calvincestari calvincestari merged commit 8e5c95a into main Sep 11, 2024
39 checks passed
@calvincestari calvincestari deleted the feature/urlrequest-cachepolicy branch September 11, 2024 19:12
BobaFetters pushed a commit to apollographql/apollo-ios that referenced this pull request Sep 11, 2024
BobaFetters pushed a commit that referenced this pull request Sep 11, 2024
6620447d enhancement: Set URLRequest cache policy on GET requests (#476)

git-subtree-dir: apollo-ios
git-subtree-split: 6620447d66a270c5605529f0a51ccfdd5d9769c9
BobaFetters pushed a commit that referenced this pull request Sep 11, 2024
…y on GET requests

git-subtree-dir: apollo-ios
git-subtree-mainline: c9f0bfd
git-subtree-split: 6620447d66a270c5605529f0a51ccfdd5d9769c9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSONRequest and HTTPRequest ignoring Apollo cachePolicy
3 participants