Description
The HTTP Client on Android (OkHttpClient), that is used for networking, doesn't have cache, so Cache-Control headers are not respected.
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment:
OS: macOS Sierra 10.12.6
Node: 8.9.0
Yarn: 1.3.2
npm: 5.5.1
Watchman: 4.9.0
Xcode: Xcode 9.0.1 Build version 9A1004
Android Studio: 3.0 AI-171.4408382
Packages: (wanted => installed)
react: 16.0.0 => 16.0.0
react-native: ^0.50.1 => 0.50.1
Steps to Reproduce
If you use fetch
to perform a request, and the response has Cache-Control
headers, then they should be respected. For example, if the response has the Cache-Control: max-age=60
headers, then, after a successful request the response should be cached. Subsequent requests in the next minute should serve the content from cache.
- Perform sequential requests for resource that has cache control set
- Check the response to realize if it came from the device http cache or the server was hit
Expected Behavior
Cache headers should be respected and subsequent requests should be served from the cache.
Actual Behavior
On iOS cache headers are respected and responses are served from the cache when necessary.
On Android cache headers are not respected and server is always hit.
Reproducible Demo
Server app that returns a random number between 0 - 100. It sets cache-control header:
https://github.com/andon/cache-tester-server/blob/master/index.js
https://evening-temple-40153.herokuapp.com/route/random
React-Native App that targets the server app and can be used to showcase the different behaviour on iOS and Android:
https://snack.expo.io/SJJLdpBkz