
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
react-native-http-cache-r
Advanced tools
React Native http cache control for both fetch/XMLHttpRequest and ImageView
由于原来仓库react-native-http-cache不再维护,导致高版本无法安装使用。 参照网上各种帖子,修复了一个版本,经测试 "react-native": "0.63.4"是可以使用的。
$ npm install react-native-http-cache-r --save
$ react-native link react-native-http-cache-r
# ios
$ cd ios & pod intall
import * as CacheManager from 'react-native-http-cache';
CacheManager.getCacheSize().then(res => {
console.log('cache size', res)
});
CacheManager.clearCache()
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.gradleinclude ':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).
FAQs
Control http cache used by fetch/XMLHttpRequest
We found that react-native-http-cache-r demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.