1+ import { LRUCache } from 'lru-cache' ;
12import type { OrchestratorApi } from './OrchestratorApi' ;
23
34export 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