-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.js
More file actions
40 lines (34 loc) · 768 Bytes
/
Copy pathcache.js
File metadata and controls
40 lines (34 loc) · 768 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
37
38
39
40
/**
* @param {string} key
* @param {string|number} data
* @param {number} ttl=0
* @param {object|null} [metadata=null]
* @param {string} [ttlType='expirationTtl']
*/
export const setCache = (
key,
data,
ttl = 0,
metadata = null,
ttlType = 'expirationTtl',
) => {
let options = {}
if (metadata && typeof metadata === 'object') {
options.metadata = metadata
}
if (ttl > 0) {
options[ttlType] = ttl >= 60 ? ttl : 60
}
return KVSTORE.put(key, data, options)
}
export const getCache = async key => {
const { value, metadata } = await KVSTORE.getWithMetadata(key)
return { value, metadata }
}
/**
* delete key from store
* @param {string} key
*/
export const deleteCache = async key => {
return KVSTORE.delete(key)
}