-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMySegmentsCacheInMemory.ts
More file actions
49 lines (34 loc) · 1017 Bytes
/
MySegmentsCacheInMemory.ts
File metadata and controls
49 lines (34 loc) · 1017 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
41
42
43
44
45
46
47
48
49
import { AbstractMySegmentsCacheSync } from '../AbstractMySegmentsCacheSync';
/**
* Default MySegmentsCacheInMemory implementation that stores MySegments in memory.
* Supported by all JS runtimes.
*/
export class MySegmentsCacheInMemory extends AbstractMySegmentsCacheSync {
private segmentCache: Record<string, boolean> = {};
private cn?: number;
protected addSegment(name: string): boolean {
if (this.segmentCache[name]) return false;
this.segmentCache[name] = true;
return true;
}
protected removeSegment(name: string): boolean {
if (!this.segmentCache[name]) return false;
delete this.segmentCache[name];
return true;
}
isInSegment(name: string): boolean {
return this.segmentCache[name] === true;
}
protected setChangeNumber(changeNumber?: number) {
this.cn = changeNumber;
}
getChangeNumber() {
return this.cn || -1;
}
protected getSegments() {
return Object.keys(this.segmentCache);
}
getKeysCount() {
return 1;
}
}