1
|
const cache = {}
|
2
|
export const updateCache = (key, value, cache_ = cache) => {
|
3
|
if (typeof value === 'object') {
|
4
|
if (!(key in cache_)) {
|
5
|
cache_[key] = {}
|
6
|
}
|
7
|
const keys = Object.keys(value)
|
8
|
if (!keys.length) {
|
9
|
return undefined
|
10
|
}
|
11
|
keys.forEach((key_) => {
|
12
|
cache_[key][key_] = updateCache(key_, value[key_], cache_[key])
|
13
|
})
|
14
|
} else if (Array.isArray(value)) {
|
15
|
cache_[key] = value.map((item) => {
|
16
|
updateCache()
|
17
|
})
|
18
|
} else {
|
19
|
cache_[key] = value
|
20
|
}
|
21
|
return cache_
|
22
|
}
|
23
|
export const getCachedData = (key) => {
|
24
|
return cache[key]
|
25
|
}
|
26
|
export default cache
|