Skip to content

Commit dcd7f4f

Browse files
committed
feat(server-core): Make OrchestratorStorage LRUCache
1 parent af7e39d commit dcd7f4f

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed
Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
import { LRUCache } from 'lru-cache';
12
import type { OrchestratorApi } from './OrchestratorApi';
23

34
export class OrchestratorStorage {
4-
protected readonly storage: Map<string, OrchestratorApi> = new Map();
5+
protected readonly storage: LRUCache<string, OrchestratorApi>;
6+
7+
public constructor(options: { compilerCacheSize?: number, maxCompilerCacheKeepAlive?: number, updateCompilerCacheKeepAlive?: boolean } = { compilerCacheSize: 100 }) {
8+
this.storage = new LRUCache<string, OrchestratorApi>({
9+
max: options.compilerCacheSize,
10+
ttl: options.maxCompilerCacheKeepAlive,
11+
updateAgeOnGet: options.updateCompilerCacheKeepAlive
12+
});
13+
}
514

615
public has(orchestratorId: string) {
716
return this.storage.has(orchestratorId);
@@ -20,37 +29,15 @@ export class OrchestratorStorage {
2029
}
2130

2231
public async testConnections() {
23-
const result = [];
24-
25-
// eslint-disable-next-line no-restricted-syntax
26-
for (const orchestratorApi of this.storage.values()) {
27-
result.push(orchestratorApi.testConnection());
28-
}
29-
30-
return Promise.all(result);
32+
return Promise.all([...this.storage.values()].map(api => api.testConnection()));
3133
}
3234

3335
public async testOrchestratorConnections() {
34-
const result = [];
35-
36-
// eslint-disable-next-line no-restricted-syntax
37-
for (const orchestratorApi of this.storage.values()) {
38-
result.push(orchestratorApi.testOrchestratorConnections());
39-
}
40-
41-
return Promise.all(result);
36+
return Promise.all([...this.storage.values()].map(api => api.testOrchestratorConnections()));
4237
}
4338

4439
public async releaseConnections() {
45-
const result = [];
46-
47-
// eslint-disable-next-line no-restricted-syntax
48-
for (const orchestratorApi of this.storage.values()) {
49-
result.push(orchestratorApi.release());
50-
}
51-
52-
await Promise.all(result);
53-
40+
await Promise.all([...this.storage.values()].map(api => api.release()));
5441
this.storage.clear();
5542
}
5643
}

0 commit comments

Comments
 (0)