Skip to content

Commit 6567102

Browse files
committed
backbone code for 'stale-if-slow' & 'stale-while-revalidate'
1 parent a05afcf commit 6567102

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,18 @@ export class OrchestratorApi {
128128
requestId: query.requestId
129129
});
130130

131+
if (query.scheduledRefresh) {
132+
throw {
133+
error: 'Continue wait',
134+
stage: null
135+
};
136+
}
137+
131138
const fromCache = await this
132139
.orchestrator
133140
.resultFromCacheIfExists(query);
134141

135-
if (
136-
!query.renewQuery &&
137-
fromCache &&
138-
!query.scheduledRefresh
139-
) {
142+
if (query.cache === 'stale-if-slow' && fromCache) {
140143
this.logger('Slow Query Warning', {
141144
query: queryForLog,
142145
requestId: query.requestId,
@@ -151,11 +154,17 @@ export class OrchestratorApi {
151154
};
152155
}
153156

157+
if (query.cache === 'stale-while-revalidate' && fromCache) {
158+
// TODO: Run background refresh
159+
return {
160+
...fromCache,
161+
slowQuery: true
162+
};
163+
}
164+
154165
throw {
155166
error: 'Continue wait',
156-
stage: !query.scheduledRefresh
157-
? await this.orchestrator.queryStage(query)
158-
: null
167+
stage: await this.orchestrator.queryStage(query)
159168
};
160169
}
161170

0 commit comments

Comments
 (0)