-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 1014 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Storage from 'react-native-storage';
import { AsyncStorage } from 'react-native';
const storage = new Storage({
// maximum capacity, default 1000
size: 1000,
// Use AsyncStorage for RN apps, or window.localStorage for web apps.
// If storageBackend is not set, data will be lost after reload.
storageBackend: AsyncStorage, // for web: window.localStorage
// expire time, default: 1 day (1000 * 3600 * 24 milliseconds).
// can be null, which means never expire.
defaultExpires: 1000 * 3600 * 24 * 365,
// cache data in the memory. default is true.
enableCache: true,
// if data was not found in storage or expired data was found,
// the corresponding sync method will be invoked returning
// the latest data.
sync: {
// we'll talk about the details later.
},
});
storage.get = async (key, defaultValue) => {
try {
const result = await storage.load({
key,
});
return result;
} catch (e) {
return defaultValue;
}
};
export default storage;