@@ -101,6 +101,30 @@ export type QueryBody = {
101101 [ key : string ] : any ;
102102} ;
103103
104+ /*
105+
106+ stale-if-slow (default) — equivalent to current renewQuery: false
107+ If refresh keys are up-to-date, returns the value from cache
108+ If refresh keys are expired, tries to return the value from the database
109+ Returns fresh value from the database if the query executed in the database until the first “Continue wait” interval is reached
110+ Returns stale value from cache otherwise
111+
112+ stale-while-revalidate — AKA “backgroundRefresh”
113+ If refresh keys are up-to-date, returns the value from cache
114+ If refresh keys are expired, returns stale data from cache
115+ Updates the cache in background
116+
117+ must-revalidate — equivalent to current renewQuery: true
118+ If refresh keys are up-to-date, returns the value from cache
119+ If refresh keys are expired, tries to return the value from the database
120+ Returns fresh value from the database even if it takes minutes and many “Continue wait” intervals
121+
122+ no-cache — AKA “forceRefresh”
123+ Skips refresh key checks
124+ Returns fresh data from the database, even if it takes minutes and many ”Continue wait” intervals
125+
126+ */
127+
104128/**
105129 * Temp (partition/lambda) table definition.
106130 */
@@ -760,6 +784,42 @@ export class QueryCache {
760784 } ) ;
761785 }
762786
787+ public async startBackgroundRefreshForQuery ( queryBody : QueryBody , preAggregationsTablesToTempTables : PreAggTableToTempTable [ ] ) {
788+ const replacePreAggregationTableNames =
789+ ( queryAndParams : string | QueryWithParams ) => (
790+ QueryCache . replacePreAggregationTableNames (
791+ queryAndParams ,
792+ preAggregationsTablesToTempTables ,
793+ )
794+ ) ;
795+
796+ const query = replacePreAggregationTableNames ( queryBody . query ) ;
797+ const { values } = queryBody ;
798+
799+ const cacheKeyQueries = this
800+ . cacheKeyQueriesFrom ( queryBody )
801+ . map ( replacePreAggregationTableNames ) ;
802+
803+ const renewalThreshold = queryBody . cacheKeyQueries ?. renewalThreshold ;
804+ const expireSecs = this . getExpireSecs ( queryBody ) ;
805+ const cacheKey = QueryCache . queryCacheKey ( queryBody ) ;
806+
807+ this . startRenewCycle (
808+ query ,
809+ values ,
810+ cacheKeyQueries ,
811+ expireSecs ,
812+ cacheKey ,
813+ renewalThreshold ,
814+ {
815+ external : queryBody . external ,
816+ requestId : queryBody . requestId ,
817+ dataSource : queryBody . dataSource ,
818+ persistent : false , // We don't need stream back as there will be no consumer
819+ }
820+ ) ;
821+ }
822+
763823 public renewQuery (
764824 query : string | QueryWithParams ,
765825 values : string [ ] ,
0 commit comments