forked from dylan-sutton-chavez/edge-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.js
More file actions
38 lines (29 loc) · 878 Bytes
/
memory.js
File metadata and controls
38 lines (29 loc) · 878 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
/*
In-memory cache backend; same shape as `cache/idb.js`. Used when `integrity:false` or IDB unavailable.
Methods are sync but callers `await` uniformly: stays interchangeable with `IdbCache`.
*/
export class MemoryCache {
constructor() {
this.cas = new Map(); // hash -> bytes
this.lockfile = new Map(); // spec -> hash
}
open() { /* no-op */ }
getBytes(hash) {
return this.cas.get(hash) ?? null;
}
putBytes(hash, bytes) {
this.cas.set(hash, bytes);
}
loadLockfile() {
return new Map(this.lockfile);
}
saveLockfile(entries) {
for (const [k, v] of entries) this.lockfile.set(k, v);
}
clear() {
this.cas.clear();
this.lockfile.clear();
}
setVersion(_version) { /* no-op: nothing to invalidate across sessions */ }
getVersion() { return null; }
}