React Native http cache control for both fetch/XMLHttpRequest and ImageView
$ npm install react-native-http-cache --save
react-native-http-cache
library from your node_modules/react-native-http-cache/ios
folder like its
described here.
Don't forget to add it to "Build Phases" of project.android/settings.gradle
include ':RCTHttpCache'
project(':RCTHttpCache').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-http-cache/android')
android/app/build.gradle
in section dependencies
...
dependencies {
...
compile project(':RCTHttpCache') // Add this line only.
}
MainApplication.java
...
import cn.reactnative.httpcache.HttpCachePackage;
// Add this line before public class MainApplication
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new HttpCachePackage(), // Add this line
new MainReactPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
-keep class com.facebook.cache.disk.DiskStorageCache {
private boolean maybeUpdateFileCacheSize();
}
import * as CacheManager from 'react-native-http-cache';
// invoke API directly when in need
CacheManager.clear();
Clear cache for all type.
Return a promise which indicate the clear state.
Get cache size for all type.
Return a promise that contain the cache size(in bytes).
Clear cache for fetch/ajax only.
Return a promise which indicate the clear state.
Get cache size for fetch/ajax only.
Return a promise that contain the cache size(in bytes).
Clear cache for ImageView only.
Return a promise which indicate the clear state.
Get cache size for ImageView only.
Return a promise that contain the cache size(in bytes).