Code Monkey home page Code Monkey logo

react-native-http-cache's Introduction

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
...
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;
  }
}
  • 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 * as CacheManager from 'react-native-http-cache';

// invoke API directly when in need
CacheManager.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

react-native-http-cache's People

Contributors

lvbingru avatar sunnylqm avatar tdzl2003 avatar yolinsoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-http-cache's Issues

Throwing error cannot find symbol method getMainDiskStorageCache() on building

I followed the doc and added react-native-http-cache to my project, but on building the app I am getting the following error

/Users/sooraj/test/node_modules/react-native-http-cache/android/src/main/java/cn/reactnative/httpcache/HttpCacheModule.java

Error:(69, 62) error: cannot find symbol method getMainDiskStorageCache()
Error:(80, 62) error: cannot find symbol method getSmallImageDiskStorageCache()

I could not figure out this issue, could you please help to fix this.

I am using React Native version 0.47

RN 0.43 不支持

无效使用: ios 报变量重复声明等错
node_modules/react-native-http-cache/ios/RCTHttpCache/RCTHttpCache.m:12:
../../react-native/React/Base/RCTBridge.h:66:1: error: duplicate interface definition for class 'RCTBridge'

android: 找不到符号

node_modules/react-native-http-cache/android/src/main/java/cn/reactnative/httpcache/HttpCacheModule.java:69: 错误: 找不到符号
FileCache cache1 = ImagePipelineFactory.getInstance().getMainDiskStorageCache();
^
符号: 方法 getMainDiskStorageCache()
位置: 类 ImagePipelineFactory
/node_modules/react-native-http-cache/android/src/main/java/cn/reactnative/httpcache/HttpCacheModule.java:80: 错误: 找不到符号
FileCache cache2 = ImagePipelineFactory.getInstance().getSmallImageDiskStorageCache();
^
符号: 方法 getSmallImageDiskStorageCache()
位置: 类 ImagePipelineFactory

"react": "16.0.0-alpha.6",
"react-native": "0.43.3",
"react-native-http-cache": "^0.2.0",

程序包okhttp3不存在

我的RN是 0.37.0, react-native run-android 后报错 /Users/Ebates/Desktop/chamWork/ReactNative/Demo/ChildhoodFood/node_modules/react-native-http-cache/android/src/main/java/cn/reactnative/httpcache/HttpCacheModule.java:15: 错误: 程序包okhttp3不存在
import okhttp3.Cache;
^
/Users/Ebates/Desktop/chamWork/ReactNative/Demo/ChildhoodFood/node_modules/react-native-http-cache/android/src/main/java/cn/reactnative/httpcache/HttpCacheModule.java:38: 错误: 找不到符号
Cache cache = OkHttpClientProvider.getOkHttpClient().cache();

请大神看看

请抓紧解决一下 安卓 getMainDiskStorageCache方法过期问题

/Users/dong/project/ejiazi/robotHousekeeper/node_modules/react-native-http-cache/android/src/main/java/cn/reactnative/httpcache/HttpCacheModule.java:69: 错误: 找不到符号
FileCache cache1 = ImagePipelineFactory.getInstance().getMainDiskStorageCache();
^
符号: 方法 getMainDiskStorageCache()
位置: 类 ImagePipelineFactory
/Users/dong/project/ejiazi/robotHousekeeper/node_modules/react-native-http-cache/android/src/main/java/cn/reactnative/httpcache/HttpCacheModule.java:80: 错误: 找不到符号
FileCache cache2 = ImagePipelineFactory.getInstance().getSmallImageDiskStorageCache();
^
符号: 方法 getSmallImageDiskStorageCache()
位置: 类 ImagePipelineFactory
2 个错误
:react-native-http-cache:compileReleaseJavaWithJavac FAILED

如何获取缓存大小

在我调用了这个方法后,CacheManager.getHttpCacheSize()),我获得了一个对象。{"_40":0,"_65":0,"_55":null,"_72":null}是什么意思?

What is the path set for cleanup

Hello, I would like to ask iOS internal is to clean up all the files under the cache file or what, what is the path set to clean

package apk build failed

I use command "gradlew assembleRelease --console plain" build my project get error info:

error: failed linking references.
:react-native-http-cache:verifyReleaseResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-http-cache:verifyReleaseResources'.

com.android.ide.common.process.ProcessException: Failed to execute aapt

How can I solve this problem? Please give me some advice,Thanks!

environment:
"react": "16.6.3",
"react-native": "0.57.8",
"react-native-http-cache": "^0.2.0",

How can i use it.

Hello
1.install react-native-http-cache,
2.import {getImageCacheSize,clearImageCache} from 'react-native-http-cache'; in my project.
i can't use it to clearCache. i can't see the example code about how to use it,give me a tip.

按照README配置android不成功?

您好,完全是按照README配置的android,却并不能成功运行。抛出这种形式的错误呢?能帮忙看下什么问题不?
Warning: /Users/dd_fly/fangge_android/android/app/src/main/AndroidManifest.xml:14:5-80 Warning:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:14:5-80 duplicated with element declared at AndroidManifest.xml:10:5-80
/Users/dd_fly/fangge_android/android/app/src/main/AndroidManifest.xml:14:5-80 Warning:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:14:5-80 duplicated with element declared at AndroidManifest.xml:10:5-80
:app:processDebugResources
:app:generateDebugSources
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac
/Users/dd_fly/fangge_android/android/app/src/main/java/com/veryside/MainActivity.java:13: 错误: 找不到符号
protected void onCreate(Bundle savedInstanceState) {
^
符号: 类 Bundle
位置: 类 MainActivity
/Users/dd_fly/fangge_android/android/app/src/main/java/com/veryside/MainActivity.java:14: 错误: 找不到符号
mReactInstanceManager = ReactInstanceManager.builder()
^
符号: 变量 mReactInstanceManager
位置: 类 MainActivity
/Users/dd_fly/fangge_android/android/app/src/main/java/com/veryside/MainActivity.java:21: 错误: 找不到符号
.setInitialLifecycleState(LifecycleState.RESUMED)
^
符号: 变量 LifecycleState
位置: 类 MainActivity
/Users/dd_fly/fangge_android/android/app/src/main/java/com/veryside/MainActivity.java:18: 错误: 找不到符号
.addPackage(new MainReactPackage())
^
符号: 类 MainReactPackage
位置: 类 MainActivity
/Users/dd_fly/fangge_android/android/app/src/main/java/com/veryside/MainActivity.java:14: 错误: 找不到符号
mReactInstanceManager = ReactInstanceManager.builder()
^
符号: 变量 ReactInstanceManager
位置: 类 MainActivity
5 个错误
:app:compileDebugJavaWithJavac FAILED

CacheManager.clearImageCache()

Image URL is same from backend but image is updating at backend. But in android app it is showing old image only. I used following code but still its showing old image only. I reloaded several times. Please help me out. But in browser its showing new image.
CacheManager.clearImageCache().then((response) =>{
console.log('clear cache1');
});

build error 构建错误

(说实话我已经不抱什么希望了,五年没更的库)

ENV INFO

$ npx react-native info
info Fetching system and libraries information...
System:
    OS: Linux 5.4 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (2) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
    Memory: 2.53 GB / 3.84 GB
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 19.6.0 - ~/nvm/current/bin/node
    Yarn: Not Found
    npm: 9.4.0 - ~/nvm/current/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 31, 32, 33
      Build Tools: 30.0.3, 33.0.0
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 11.0.14.1 - /home/*/java/current/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0
    react-native: 0.71.4 => 0.71.4
  npmGlobalPackages:
    *react-native*: Not Found

OUTPUT

FAILURE: Build failed with an exception.

* Where:
Build file '/workspaces/*/android/app/build.gradle' line: 177

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method compile() for arguments [project ':RCTHttpCache'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

CacheManager.clear() not a function error

Added in react-native file
import * as CacheManager from 'react-native-http-cache';
// invoke API directly when in need
CacheManager.clear();

CacheManager.clear is not a function

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.