1
1
/* eslint-disable global-require,no-return-assign */
2
2
import crypto from 'crypto' ;
3
3
import fs from 'fs-extra' ;
4
- import LRUCache from 'lru-cache' ;
4
+ import { LRUCache } from 'lru-cache' ;
5
5
import isDocker from 'is-docker' ;
6
6
import pLimit from 'p-limit' ;
7
7
@@ -203,8 +203,10 @@ export class CubejsServerCore {
203
203
204
204
this . compilerCache = new LRUCache < string , CompilerApi > ( {
205
205
max : this . options . compilerCacheSize || 250 ,
206
- maxAge : this . options . maxCompilerCacheKeepAlive ,
207
- updateAgeOnGet : this . options . updateCompilerCacheKeepAlive
206
+ ttl : this . options . maxCompilerCacheKeepAlive ,
207
+ updateAgeOnGet : this . options . updateCompilerCacheKeepAlive ,
208
+ // needed to clear the setInterval timer for proactive cache internal cleanups
209
+ dispose : ( v ) => v . dispose ( ) ,
208
210
} ) ;
209
211
210
212
if ( this . options . contextToAppId ) {
@@ -224,7 +226,7 @@ export class CubejsServerCore {
224
226
// proactively free up old cache values occasionally
225
227
if ( this . options . maxCompilerCacheKeepAlive ) {
226
228
this . maxCompilerCacheKeep = setInterval (
227
- ( ) => this . compilerCache . prune ( ) ,
229
+ ( ) => this . compilerCache . purgeStale ( ) ,
228
230
this . options . maxCompilerCacheKeepAlive
229
231
) ;
230
232
}
@@ -554,7 +556,7 @@ export class CubejsServerCore {
554
556
await this . orchestratorStorage . releaseConnections ( ) ;
555
557
556
558
this . orchestratorStorage . clear ( ) ;
557
- this . compilerCache . reset ( ) ;
559
+ this . compilerCache . clear ( ) ;
558
560
559
561
this . reloadEnvVariables ( ) ;
560
562
@@ -714,6 +716,9 @@ export class CubejsServerCore {
714
716
standalone : this . standalone ,
715
717
allowNodeRequire : options . allowNodeRequire ,
716
718
fastReload : options . fastReload || getEnv ( 'fastReload' ) ,
719
+ compilerCacheSize : this . options . compilerCacheSize || 250 ,
720
+ maxCompilerCacheKeepAlive : this . options . maxCompilerCacheKeepAlive ,
721
+ updateCompilerCacheKeepAlive : this . options . updateCompilerCacheKeepAlive
717
722
} ,
718
723
) ;
719
724
}
@@ -871,6 +876,8 @@ export class CubejsServerCore {
871
876
clearInterval ( this . maxCompilerCacheKeep ) ;
872
877
}
873
878
879
+ this . compilerCache . clear ( ) ;
880
+
874
881
if ( this . scheduledRefreshTimerInterval ) {
875
882
await this . scheduledRefreshTimerInterval . cancel ( ) ;
876
883
}
@@ -914,6 +921,8 @@ export class CubejsServerCore {
914
921
} ;
915
922
916
923
public async shutdown ( ) {
924
+ this . compilerCache . clear ( ) ;
925
+
917
926
if ( this . devServer ) {
918
927
if ( ! process . env . CI ) {
919
928
process . removeListener ( 'uncaughtException' , this . onUncaughtException ) ;
0 commit comments