cachefetch_rn

using AsyncStorage to cache fetch's response,only for RN,not for browser


Keywords
cache, fetch, react-native
License
GPL-2.0+
Install
npm install cachefetch_rn@0.0.5

Documentation

cachefetch_rn

  • configurable cacheFetch for react-native,using AsyncStorage to cache
  • cacheFetch inherits the same API as fetch()

Usage

  • Install :npm install cacheFetch_RN
  • example:
import { AsyncStorage } from 'react-native';
import { clearFetchCache, makeCacheFetch } from 'cachefetch_rn';

const headersPopulator = (headers) => {
  //headers is a plain object
  console.log('before populate', headers);
  delete headers['Fc-Csrf'];
  delete headers['Cookie'];
  console.log('after populate', headers);
  return headers;
};
const cacheFetch = makeCacheFetch({
  AsyncStorage: AsyncStorage,
  fetch: global.fetch,
  headersPopulator: headersPopulator,
  logger: console,
});
global.fetch = cacheFetch; //optional,if you want all fetch to be cacheFetch 

API

  • clearFetchCache, clear all cache
  • makeCacheFetch(...),see code for detail