-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
81 lines (67 loc) · 1.14 KB
/
example.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
72
73
74
75
76
77
78
79
80
81
const { MultiKeyObject } = require("./dist");
const cache = new MultiKeyObject();
//Automatically converts key fields to strings
cache.set({
a: 123,
b: "hello",
c: BigInt("123")
}, {
d: 333,
});
console.log("cache.get:", cache.get({
a: "123",
b: "hello",
c: "123"
}));
cache.set({
a: "123",
b: "hello",
c: "123"
}, {
d: 555,
e: {
f: BigInt("123")
}
});
cache.set({
a: "555",
b: "hello",
c: "123"
}, {
d: 333,
e: {
f: BigInt("123")
}
});
console.log("cache.has:", cache.has({
a: "555",
b: "hello",
c: "123"
}));
console.log("cache.get:", cache.get({
a: "123",
b: "hello",
c: "123"
}));
console.log("for of cache:");
for (let [key, value] of cache) {
console.log(key, value);
}
console.log("for of cache.keys:");
for (let key of cache.keys()) {
console.log(key);
}
console.log("for of cache.values:");
for (let value of cache.values()) {
console.log(value);
}
cache.delete({
a: "123",
b: "hello",
c: "123"
});
console.log("cache.forEach after delete:");
cache.forEach((value, key) => console.log(key, value));
cache.clear();
console.log("cache.forEach after clear:");
cache.forEach((value, key) => console.log(key, value));