Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orzhtml/react-native-orzhtml-httpcache
Control http cache used by fetch/XMLHttpRequest
https://github.com/orzhtml/react-native-orzhtml-httpcache
Last synced: 10 days ago
JSON representation
Control http cache used by fetch/XMLHttpRequest
- Host: GitHub
- URL: https://github.com/orzhtml/react-native-orzhtml-httpcache
- Owner: orzhtml
- License: mit
- Created: 2020-08-17T01:24:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-17T10:21:50.000Z (over 4 years ago)
- Last Synced: 2024-04-25T03:42:32.123Z (9 months ago)
- Language: Java
- Size: 14.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
React Native http cache control for both fetch/XMLHttpRequest and ImageView
- [√] iOS
- [√] Android## Installation
```sh
$ npm install react-native-orzhtml-httpcache --save
```## iOS: Linking in your XCode project
- Link `react-native-orzhtml-httpcache` library from your `node_modules/react-native-orzhtml-httpcache/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-orzhtml-httpcache/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.orzhtml.httpcache.HttpCachePackage;
// Add this line before public class MainApplicationpublic 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-orzhtml-httpcache';// invoke API directly when in need
CacheManager.clearCache();```
## API Documentation
#### clearCache()
Clear cache for all type.
Return a promise which indicate the clear state.
#### getCacheSize()
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).