let storage = new Storage({
// 最大容量,默认值1000条数据循环存储
size: 500,
// 如果不指定则数据只会保存在内存中,重启后即丢失
storageBackend: AsyncStorage,
// 数据过期时间,默认一整天(1000 * 3600 * 24 毫秒),设为null则永不过期
defaultExpires: null,
// 读写时在内存中缓存数据。默认启用。
enableCache: true,
});
export function _cache(keys, value) {
//缓存
storage.save({
key: keys,
data: value, //要缓存的数据
expires: 1000 * 3600
});
}
//缓存
_cache('ListPictureData', this._ListPicturesData);
//key //value
//删除缓存
export function _deleteCache(keys) {
storage.clearMapForKey(keys);
}
//获取缓存
storage.load({
key: 'ListPictureData',
autoSync: true,
syncInBackground: false,
}).then(ret => {
this._ListPicturesData = ret;
//初始化渲染
this.setState({
dataSource: this.state.dataSource.cloneWithRows(this._ListPicturesData),
});
}).catch(err => {
});
//this._ListPicturesData === rowData
git 原始缓存介绍地址 https://github.com/sunnylqm/react-native-storage/blob/master/README-CHN.md