Skip to content

Commit d86e71f

Browse files
committed
InMemoryCacheProvider added
1 parent 3eae4e3 commit d86e71f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { InternalCacheProvider } from './CacheProvider';
2+
import { EntityDataObject } from './EntityDataObject';
3+
import { ResultTree } from './ResultTree';
4+
5+
6+
export class InMemoryCacheProvider implements InternalCacheProvider {
7+
private bdos = new Map<string, EntityDataObject>();
8+
private resultTrees = new Map<string, ResultTree>();
9+
constructor(private _keyId: string) { }
10+
11+
setResultTree(queryId: string, rt: ResultTree): Promise<void> {
12+
this.resultTrees.set(queryId, rt);
13+
return Promise.resolve();
14+
}
15+
// TODO: Should this be in the cache provider? This seems common along all CacheProviders.
16+
async getResultTree(queryId: string): Promise<ResultTree | undefined> {
17+
return this.resultTrees.get(queryId);
18+
}
19+
createGlobalId(): string {
20+
return crypto.randomUUID();
21+
}
22+
updateBackingData(backingData: EntityDataObject): Promise<void> {
23+
this.bdos.set(backingData.globalID, backingData);
24+
return Promise.resolve();
25+
}
26+
async getBdo(globalId: string): Promise<EntityDataObject> {
27+
if (!this.bdos.has(globalId)) {
28+
this.bdos.set(globalId, new EntityDataObject(globalId));
29+
}
30+
// Because of the above, we can guarantee that there will be a BDO at the globalId.
31+
return this.bdos.get(globalId)!;
32+
}
33+
close(): Promise<void> {
34+
// TODO: Noop
35+
return Promise.resolve();
36+
}
37+
}

0 commit comments

Comments
 (0)