Skip to content

Commit 3162ea8

Browse files
committed
add top compile cache in the server core
1 parent aac33c0 commit 3162ea8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/cubejs-server-core/src/core/CompilerApi.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export class CompilerApi {
116116

117117
protected readonly compiledScriptCache: LRUCache<string, vm.Script>;
118118

119+
protected readonly compiledYamlCache: LRUCache<string, string>;
120+
121+
protected readonly compiledJinjaCache: LRUCache<string, string>;
122+
119123
protected compiledScriptCacheInterval?: NodeJS.Timeout;
120124

121125
protected graphqlSchema?: GraphQLSchema;
@@ -145,16 +149,32 @@ export class CompilerApi {
145149
this.sqlCache = options.sqlCache;
146150
this.standalone = options.standalone;
147151
this.nativeInstance = this.createNativeInstance();
152+
153+
// Caching stuff
148154
this.compiledScriptCache = new LRUCache({
149155
max: options.compilerCacheSize || 250,
150156
ttl: options.maxCompilerCacheKeepAlive,
151157
updateAgeOnGet: options.updateCompilerCacheKeepAlive
152158
});
159+
this.compiledYamlCache = new LRUCache({
160+
max: options.compilerCacheSize || 250,
161+
ttl: options.maxCompilerCacheKeepAlive,
162+
updateAgeOnGet: options.updateCompilerCacheKeepAlive
163+
});
164+
this.compiledJinjaCache = new LRUCache({
165+
max: options.compilerCacheSize || 250,
166+
ttl: options.maxCompilerCacheKeepAlive,
167+
updateAgeOnGet: options.updateCompilerCacheKeepAlive
168+
});
153169

154170
// proactively free up old cache values occasionally
155171
if (this.options.maxCompilerCacheKeepAlive) {
156172
this.compiledScriptCacheInterval = setInterval(
157-
() => this.compiledScriptCache.purgeStale(),
173+
() => {
174+
this.compiledScriptCache.purgeStale();
175+
this.compiledYamlCache.purgeStale();
176+
this.compiledJinjaCache.purgeStale();
177+
},
158178
this.options.maxCompilerCacheKeepAlive
159179
);
160180
}

0 commit comments

Comments
 (0)