@@ -70,6 +70,7 @@ export type DataSchemaCompilerOptions = {
70
70
compileContext ?: any ;
71
71
allowNodeRequire ?: boolean ;
72
72
compiledScriptCache : LRUCache < string , vm . Script > ;
73
+ compiledYamlCache : LRUCache < string , string > ;
73
74
} ;
74
75
75
76
export type TranspileOptions = {
@@ -145,6 +146,8 @@ export class DataSchemaCompiler {
145
146
146
147
private readonly compiledScriptCache : LRUCache < string , vm . Script > ;
147
148
149
+ private readonly compiledYamlCache : LRUCache < string , string > ;
150
+
148
151
private compileV8ContextCache : vm . Context | null = null ;
149
152
150
153
// FIXME: Is public only because of tests, should be private
@@ -178,6 +181,7 @@ export class DataSchemaCompiler {
178
181
this . workerPool = null ;
179
182
this . compilerId = options . compilerId || 'default' ;
180
183
this . compiledScriptCache = options . compiledScriptCache ;
184
+ this . compiledYamlCache = options . compiledYamlCache ;
181
185
}
182
186
183
187
public compileObjects ( compileServices : CompilerInterface [ ] , objects , errorsReport : ErrorReporter ) {
@@ -635,6 +639,15 @@ export class DataSchemaCompiler {
635
639
errorsReport : ErrorReporter ,
636
640
{ cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId, stage } : TranspileOptions
637
641
) : Promise < ( FileContent | undefined ) > {
642
+ const cacheKey = crypto . createHash ( 'md5' ) . update ( JSON . stringify ( file . content ) ) . digest ( 'hex' ) ;
643
+
644
+ if ( this . compiledYamlCache . has ( cacheKey ) ) {
645
+ file . content = this . compiledYamlCache . get ( cacheKey ) ! ;
646
+ file . convertedToJs = true ;
647
+
648
+ return { ...file } ;
649
+ }
650
+
638
651
/* if (getEnv('transpilationNative')) {
639
652
640
653
} else */ if ( getEnv ( 'transpilationWorkerThreads' ) ) {
@@ -653,6 +666,8 @@ export class DataSchemaCompiler {
653
666
file . content = res . content ;
654
667
file . convertedToJs = true ;
655
668
669
+ this . compiledYamlCache . set ( cacheKey , res . content ) ;
670
+
656
671
return { ...file , content : res . content } ;
657
672
} else {
658
673
const transpiledFile = this . yamlCompiler . transpileYamlFile ( file , errorsReport ) ;
@@ -665,6 +680,8 @@ export class DataSchemaCompiler {
665
680
file . convertedToJs = true ;
666
681
}
667
682
683
+ this . compiledYamlCache . set ( cacheKey , transpiledFile ?. content || '' ) ;
684
+
668
685
return transpiledFile ;
669
686
}
670
687
}
0 commit comments