ReactNativeクリアキャッシュライブラリreact-native-http-cacheuse



React Native Clear Cache Library React Native Http Cache Use



1.react-native-http-cache: https://github.com/reactnativecn/react-native-http-cache

2.Androidの問題を変更します



問題 :ドキュメントに従ってインストールした後、AndroidはメソッドgetMainDiskStorageCache()を報告します

解決:
ソースを変更し、パスnode_modules >> react-native-http-cache >> android >> src >> main >> java >> cn >> reactnative >> httpcache >> HttpCacheModuleを見つけます。 Java
getImageCacheSize()メソッドのこれら2つのメソッドを置き換えます



//FileCache cache1 = ImagePipelineFactory.getInstance().getMainDiskStorageCache() FileCache cache1 = ImagePipelineFactory.getInstance().getMainFileCache() //FileCache cache2 = ImagePipelineFactory.getInstance().getSmallImageDiskStorageCache() FileCache cache2 = ImagePipelineFactory.getInstance().getSmallImageFileCache()

画像

3.キャッシュサイズを取得し、キャッシュをクリアします

  • キャッシュメソッドを取得します:CacheManager.getCacheSize()
  • キャッシュメソッドをクリアします:CacheManager.clearCache()
/** * Get the cache * */ getcache() { CacheManager.getCacheSize().then((value) => { let size = Math.round((value / 1024 / 1024) * 100) / 100 + 'M' console.log(size) }, (erro) => { console.log(erro) }) } /** * clear cache * */ clean() { CacheManager.clearCache() this.getcache() }