此项目拷贝于 react-native-http-cacahe,因为源代码有错误,所以此为修正版本
- iOS
- Android
$ 在你的package.json 中加入https://github.com/jeffzing/cacheMannager.git即可接入
- Link
react-native-http-cache
library from yournode_modules/react-native-http-cache/ios
folder like its described here. Don't forget to add it to "Build Phases" of project.
- Add following lines into
android/settings.gradle
include ':RCTHttpCache'
project(':RCTHttpCache').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-http-cache/android')
- Add following lines into your
android/app/build.gradle
in sectiondependencies
...
dependencies {
...
compile project(':RCTHttpCache') // Add this line only.
}
- Add following lines into
MainActivity.java
...
import cn.reactnative.httpcache.HttpCachePackage;
// Add this line before public class MainActivity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new HttpCachePackage()) // Add this line
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
}
}
- Add these lines to 'proguard-rules.pro' if you need to minify your java code:
-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).
- Deng Yun from React-Native-CN
- Lv Bingru from React-Native-CN