-
Notifications
You must be signed in to change notification settings - Fork 0
/
k6caches.js
36 lines (29 loc) · 1.13 KB
/
k6caches.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
import k6cache from 'k6/x/k6cache';
import { sleep } from 'k6';
export default function () {
k6cache.createCacheWithExpiryInSeconds(1)
k6cache.putToCache('key', 'value')
k6cache.createWithExpiryInSeconds('token', 1)
k6cache.putToNamedCache("token", "myToken", "value")
console.log(`Expecting default key-value to expire, should be 'value', was: ${k6cache.getFromCache('key')}`)
console.log(`Expecting named key-value to expire, should be 'value', was: ${k6cache.getFromNamedCache('token', "myToken")}`)
sleep(2)
console.log(`Expecting default key-value to expire, should be null: ${k6cache.getFromCache('key')}`)
console.log(`Expecting named key-value to expire, should be null: ${k6cache.getFromNamedCache('token', "myToken")}`)
// true-false tests finished
try {
k6cache.getFromNamedCache("invalidCacheName", "irrelevantKey")
} catch (error) {
console.log(error)
}
try {
k6cache.putToNamedCache("invalidCacheName", "irrelevantKey")
} catch (error) {
console.log(error)
}
try {
k6cache.removeFromNamedCache("invalidCacheName", "irrelevantKey")
} catch (error) {
console.log(error)
}
}