clear cache
npm install @pliybird/react-native-clear-cachegetCacheSize - 获取缓存大小@callBack - Function - 回调函数@cacheSize - String - 缓存大小@unit - String - 缓存大小单位(B KB MB G)#
- runClearCache - 清除缓存
- @callBack - Function - 回调函数
#
import clear from 'react-native-clear-cache';
constructor () {
super();
this.state = {
cacheSize:"",
unit:"",
}
clear.getCacheSize((value,unit)=>{
this.setState({
cacheSize:value, //缓存大小
unit:unit //缓存单位
})
});
}
render() {
return (
缓存大小{this.state.cacheSize}{this.state.unit}
);
}
clearCache(){
clear.runClearCache(()=>{
console.log("清除成功");
clear.getCacheSize((value,unit)=>{
this.setState({
cacheSize:value, //缓存大小
unit:unit //缓存单位
})
});
});
}
version>=0.60.0
auto link
version<0.60.0
执行此命令
react-native link
android/setting.gradle ```
...
include ':reactNativeClearCache'
project(':reactNativeClearCache').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-clear-cache/android')
2. 设置 android/app/build.gradle
``
...
dependencies {
...
compile project(':reactNativeClearCache')
}
3. 注册模块 (到 MainApplication.java)
`
import com.example.qiepeipei.react_native_clear_cache.ClearCachePackage;
public class MainApplication extends Application implements ReactApplication {
......
@Override
protected List
return Arrays.
new MainReactPackage(),
new new ClearCachePackage() //<--- 添加
);
}
......
}
`
npx pod-install`