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;
},
version: '1.0.0'
};
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);