Skip to content

Latest commit

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

适配0.57.1

compileSdkVersion 27
buildToolsVersion "27.0.3"

React Native http cache control for both fetch/XMLHttpRequest and ImageView

  • iOS
  • Android

Installation

$ 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. 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
...
importcn.reactnative.httpcache.HttpCachePackage;
// Add this line before public class MainApplicationpublicclassMainApplicationextendsApplicationimplementsReactApplication {
privatefinalReactNativeHostmReactNativeHost = newReactNativeHost(this) {
@OverrideprotectedbooleangetUseDeveloperSupport() {
returnBuildConfig.DEBUG;
}
@OverrideprotectedList<ReactPackage> getPackages() {
returnArrays.<ReactPackage>asList(
newHttpCachePackage(), // Add this linenewMainReactPackage()
);
}
};
@OverridepublicReactNativeHostgetReactNativeHost() {
returnmReactNativeHost;
}
}
  • 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!

import*asCacheManagerfrom'react-native-http-cache';// invoke API directly when in needCacheManager.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

About

Native module to control react native http cache

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages