-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCache.js
More file actions
36 lines (29 loc) · 669 Bytes
/
Cache.js
File metadata and controls
36 lines (29 loc) · 669 Bytes
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
// import React from 'react';
import AsyncStorage from '@react-native-community/async-storage';
/*
Usage:
import Cache from 'app/src/utils/teal-rn/Cache';
Cache.get(key).then(value => {})
Cache.set(key,value)
*/
const Cache = {
set: async (key, value) => {
try {
return await AsyncStorage.setItem(key, JSON.stringify(value))
} catch (e) {
console.log('Cache Error',e);
}
},
get: async key => {
try {
const value = await AsyncStorage.getItem(key)
if(value !== null){
return JSON.parse(value);
}
return value;
} catch(e) {
console.log('Cache Error',e);
}
}
};
export default Cache;