https://github.com/reactnativecn/react-native-http-cache
Native module to control react native http cache
https://github.com/reactnativecn/react-native-http-cache
Last synced: 8 months ago
JSON representation
Native module to control react native http cache
- Host: GitHub
- URL: https://github.com/reactnativecn/react-native-http-cache
- Owner: reactnativecn
- Created: 2015-12-29T09:51:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-10T13:59:07.000Z (almost 2 years ago)
- Last Synced: 2025-03-28T20:06:34.295Z (9 months ago)
- Language: Java
- Size: 20.5 KB
- Stars: 225
- Watchers: 8
- Forks: 109
- Open Issues: 30
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
React Native http cache control for both fetch/XMLHttpRequest and ImageView
- [x] iOS
- [x] Android
## Installation
```sh
$ npm install react-native-http-cache --save
```
## iOS: Linking in your XCode project
- Link `react-native-http-cache` library from your `node_modules/react-native-http-cache/ios` folder like its
[described here](http://facebook.github.io/react-native/docs/linking-libraries-ios.html).
Don't forget to add it to "Build Phases" of project.
## Android: Linking to your gradle 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 section `dependencies`
```
...
dependencies {
...
compile project(':RCTHttpCache') // Add this line only.
}
```
- Add following lines into `MainApplication.java`
```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 getPackages() {
return Arrays.asList(
new HttpCachePackage(), // Add this line
new MainReactPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
```
- 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();
}
```
## JavaScript: import all and invoke!
```js
import * as CacheManager from 'react-native-http-cache';
// invoke API directly when in need
CacheManager.clear();
```
## API Documentation
#### clear()
Clear cache for all type.
Return a promise which indicate the clear state.
#### getSize()
Get cache size for all type.
Return a promise that contain the cache size(in bytes).
#### clearHttpCache()
Clear cache for fetch/ajax only.
Return a promise which indicate the clear state.
#### getHttpCacheSize()
Get cache size for fetch/ajax only.
Return a promise that contain the cache size(in bytes).
#### clearImageCache()
Clear cache for ImageView only.
Return a promise which indicate the clear state.
#### getImageCacheSize()
Get cache size for ImageView only.
Return a promise that contain the cache size(in bytes).
## Authors
- [Deng Yun](https://github.com/tdzl2003) from [React-Native-CN](https://github.com/reactnativecn)
- [Lv Bingru](https://github.com/lvbingru) from [React-Native-CN](https://github.com/reactnativecn)