From 26793a052a8d6d0b5f0a9f43103fe7f6d4c742f9 Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Wed, 16 Jan 2019 20:56:23 -0800 Subject: [PATCH] Add HTTP cache by default (like iOS) (#18348) Summary: On iOS, the cache is enabled by default but it's not the case on Android. This PR adds 10Mo of HTTP cache by default. 10Mo was chosen arbitrarily. Fixes #16795 I wrote it so there's no breaking change for those already using the `OkHttpClientProvider.createClient` and `OkHttpClientProvider.createClientBuilder` public methods. 1. react-native init TestAndroidCache 2. Followed https://facebook.github.io/react-native/docs/android-building-from-source.html to build with this branch as react-native 3. Added the following code in the App.js (with correct URL_WITH_CACHE_CONTROL) 4. Made sure the debugger is closed 5. Throttled my mac's network speed with the `Network link conditioner` (edge) 6. Tapped "Fetch", it shows ~4000 7. Tapped "Fetch" again, it shows ~6 ```js import React, { Component } from 'react'; import { StyleSheet, Alert, View, Button } from 'react-native'; type Props = {}; export default class App extends Component { fetch = () => { const start = Date.now(); fetch('{URL_WITH_CACHE_CONTROL}').then(() => { const diff = Date.now() - start; Alert.alert(diff.toString()); }); }; render() { return (