web-local-cache

1.0.7 • Public • Published

web-local-cache

cache data with localStorage

API

import LocalCache from 'web-local-cache';

// register
const data_key = {
    url: 'https://xx.xx.json',
    header: {},
    data: {},
    success: (resp) => {
        return resp.data;
    },
    error: (e) => {
        console.log(e);
    },
    version: '1.0.0' //version format must be x.x.x
};

const UniqueData = LocalCache.register('unique', {
    data_key
});

// get
const { data_key } = UniqueData;
data_key.then((data) => {
    console.log(data);
});

// clear all
LocalCache.clear('unique');

// clear property
UniqueData.clear('data_key');

We used the native fetch method as default to get data. If you want to change fetch method, you can pass a fetch get method which will return a standard promise object as the third argument:

LocalCache.register('unique', {
   // data options
}, fetchGetMethod);

Package Sidebar

Install

npm i web-local-cache

Weekly Downloads

8

Version

1.0.7

License

ISC

Last publish

Collaborators

  • papergou