Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 1.09 KB

custom-drivers.md

File metadata and controls

26 lines (17 loc) · 1.09 KB

Using your own driver for caching

This wrapper has been written with the goal of being storage-agnostic. This means that by default, it will make use of react-native's AsyncStorage API, but feel free to write your own driver and use anything you want, like the amazing realm.

Your custom driver must implement these 3 methods that are promises.

  • getItem(key: string): Promise;
  • setItem(key: string, value: string, callback?: (err: any, value: string) => any): Promise;
  • removeItem(key: string): Promise;

SQLite Driver (react-native only)

As of 2.2.0, an SQLite driver is baked-in with the module. Install SQLite in your project by following these instructions and set it as your custom driver like this :

import APIpeline, { drivers } from 'apipeline';
import SQLite from 'react-native-sqlite-storage';

// ...

const api = new APIpeline(API_OPTIONS, API_SERVICES);

drivers.sqliteDriver(SQLite, { debug: false }).then((driver) => {
    api.setCacheDriver(driver);
});