Skip to content

Commit d1ff8c8

Browse files
committed
add proactive cache cleanup
1 parent af7e39d commit d1ff8c8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ export class CompilerApi {
3535
ttl: options.maxCompilerCacheKeepAlive,
3636
updateAgeOnGet: options.updateCompilerCacheKeepAlive
3737
});
38+
39+
// proactively free up old cache values occasionally
40+
if (this.options.maxCompilerCacheKeepAlive) {
41+
this.compiledScriptCacheInterval = setInterval(
42+
() => this.compiledScriptCache.purgeStale(),
43+
this.options.maxCompilerCacheKeepAlive
44+
);
45+
}
46+
}
47+
48+
dispose() {
49+
if (this.compiledScriptCacheInterval) {
50+
clearInterval(this.compiledScriptCacheInterval);
51+
}
3852
}
3953

4054
setGraphQLSchema(schema) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ export class CubejsServerCore {
204204
this.compilerCache = new LRUCache<string, CompilerApi>({
205205
max: this.options.compilerCacheSize || 250,
206206
ttl: this.options.maxCompilerCacheKeepAlive,
207-
updateAgeOnGet: this.options.updateCompilerCacheKeepAlive
207+
updateAgeOnGet: this.options.updateCompilerCacheKeepAlive,
208+
// needed to clear the setInterval timer for proactive cache internal cleanups
209+
dispose: (v) => v.dispose(),
208210
});
209211

210212
if (this.options.contextToAppId) {

0 commit comments

Comments
 (0)