-
Notifications
You must be signed in to change notification settings - Fork 6
/
data-cache.mjs
54 lines (44 loc) · 1.26 KB
/
data-cache.mjs
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
import jsonLike from "../json-like/json-like.js";
import { inspect } from "util";
export function DataCache(db) {
const self = {
update,
getObject,
getFunCall,
getFun,
getCodeFile,
heapLookup,
getHeapObject
};
const log = db.log;
const map = new Map();
async function update(snapshot) {
for (let key in snapshot.attachments) {
let data = snapshot.attachments[key];
if (key.startsWith("Object/")) {
data = jsonLike.parse(data, true);
}
// log.write(`adding map entry: ${key} = ${inspect(data)}\n`);
map.set(key, data);
}
}
function getObject(id) {
return map.get("Object/" + id);
}
function getFunCall(id) {
return map.get("FunCall/" + id);
}
function getFun(id) {
return map.get("Fun/" + id);
}
function heapLookup(heapVersion, heapId) {
return map.get("HeapRef/" + heapVersion + "/" + heapId);
}
function getHeapObject(heapVersion, heapId) {
return getObject(heapLookup(heapVersion, heapId));
}
function getCodeFile(id) {
return map.get("CodeFile/" + id);
}
return self;
}