@@ -110,26 +110,29 @@ function sizeCache(config) {
110110
111111async function invalidateCache ( config ) {
112112 if ( canUseCache ( config , db ) ) {
113- const meta = await loadResource ( { ...config , cache : false } , 'meta' )
114- const upstream_deploy_date = parseInt ( meta . deploy_date )
115- const transaction = db . transaction ( "cache" , "readwrite" ) ;
116- const objectStore = transaction . objectStore ( "cache" ) ;
117- const index = objectStore . index ( "deploy_date_index" )
118- const range = IDBKeyRange . upperBound ( upstream_deploy_date , true ) ;
119- const request = index . getAllKeys ( range ) ;
113+ const meta = await loadResource ( { ...config , cache : false } , 'meta' ) ;
114+ const upstream_deploy_date = parseInt ( meta . deploy_date ) ;
115+
116+ return new Promise ( ( resolve , reject ) => {
117+ const transaction = db . transaction ( "cache" , "readwrite" ) ;
118+ const objectStore = transaction . objectStore ( "cache" ) ;
119+ const index = objectStore . index ( "deploy_date_index" ) ;
120+
121+ const range = IDBKeyRange . upperBound ( upstream_deploy_date , true ) ;
122+ const request = index . getAllKeys ( range ) ;
120123
121- request . onsuccess = ( ) => {
122- const keys = request . result ;
123- keys . forEach ( pk => {
124- objectStore . delete ( pk ) ;
125- log ( `invalidated ${ pk } ` ) ;
126- } ) ;
127- return true
128- } ;
129- request . onerror = ( ) => { throw new Error ( request . error ) ;
130- } ;
124+ request . onsuccess = ( ) => {
125+ const keys = request . result ;
126+ keys . forEach ( pk => {
127+ objectStore . delete ( pk ) ;
128+ log ( `invalidated ${ pk } ` ) ;
129+ } ) ;
130+ resolve ( true ) ;
131+ } ;
132+ request . onerror = ( ) => reject ( new Error ( request . error ) ) ;
133+ } ) ;
131134 } else {
132- throw new Error ( 'cache not available' )
135+ throw new Error ( 'cache not available' ) ;
133136 }
134137}
135138
0 commit comments