-
Notifications
You must be signed in to change notification settings - Fork 17
/
quickcache.js
71 lines (55 loc) · 1.41 KB
/
quickcache.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const weather = []
const events = []
const event = []
const hotels = []
const hotel = []
const reservation = []
function save(storeKey, value, ...itemKeys) {
const stores = {
'weather': this.weather,
'events': this.events,
'event': this.event,
'hotels': this.hotels,
'hotel': this.hotel,
'reservation': this.reservation,
}
const selected_store = stores[storeKey]
selected_store.push({ key: itemKeys.join("_"), value: JSON.stringify(value) })
}
function exist(storeKey, ...itemKeys) {
const stores = {
'weather': this.weather,
'events': this.events,
'event': this.event,
'hotels': this.hotels,
'hotel': this.hotel,
'reservation': this.reservation,
}
return stores[storeKey].some((qc) => qc.key === itemKeys.join("_"))
}
function retrieve(storeKey, ...itemKeys) {
const stores = {
'weather': this.weather,
'events': this.events,
'event': this.event,
'hotels': this.hotels,
'hotel': this.hotel,
'reservation': this.reservation,
}
const stored_data = stores[storeKey].find((qc) => qc.key === itemKeys.join("_"))
if(stored_data) {
return JSON.parse(stored_data.value)
}
}
const QuickCache = {
weather,
events,
event,
hotels,
hotel,
reservation,
save,
retrieve,
exist,
}
export default QuickCache