@@ -9,15 +9,20 @@ const debug = _debug('cs:compiler:cache');
99
1010const host = process . env . CODESANDBOX_HOST ;
1111
12- localforage . config ( {
13- name : 'CodeSandboxApp' ,
14- storeName : 'sandboxes' , // Should be alphanumeric, with underscores.
15- description :
16- 'Cached transpilations of the sandboxes, for faster initialization time.' ,
17- } ) ;
18-
19- // Prewarm store
20- localforage . keys ( ) ;
12+ try {
13+ localforage . config ( {
14+ name : 'CodeSandboxApp' ,
15+ storeName : 'sandboxes' , // Should be alphanumeric, with underscores.
16+ description :
17+ 'Cached transpilations of the sandboxes, for faster initialization time.' ,
18+ } ) ;
19+
20+ // Prewarm store
21+ localforage . keys ( ) ;
22+ } catch ( e ) {
23+ console . warn ( 'Problems initializing IndexedDB store.' ) ;
24+ console . warn ( e ) ;
25+ }
2126
2227function shouldSaveOnlineCache ( firstRun : boolean ) {
2328 if ( ! firstRun ) {
@@ -107,24 +112,31 @@ function findCacheToUse(cache1, cache2) {
107112}
108113
109114export async function consumeCache ( manager : Manager ) {
110- const cacheData = window . __SANDBOX_DATA__ ;
111- const localData = await localforage . getItem ( manager . id ) ;
115+ try {
116+ const cacheData = window . __SANDBOX_DATA__ ;
117+ const localData = await localforage . getItem ( manager . id ) ;
112118
113- const cache = findCacheToUse ( cacheData && cacheData . data , localData ) ;
114- if ( cache ) {
115- const version = SCRIPT_VERSION ;
119+ const cache = findCacheToUse ( cacheData && cacheData . data , localData ) ;
120+ if ( cache ) {
121+ const version = SCRIPT_VERSION ;
116122
117- if ( cache . version === version ) {
118- debug (
119- `Loading cache from ${ cache === localData ? 'localStorage' : 'API' } ` ,
120- cache
121- ) ;
123+ if ( cache . version === version ) {
124+ debug (
125+ `Loading cache from ${ cache === localData ? 'localStorage' : 'API' } ` ,
126+ cache
127+ ) ;
122128
123- await manager . load ( cache ) ;
129+ await manager . load ( cache ) ;
124130
125- return true ;
131+ return true ;
132+ }
126133 }
127- }
128134
129- return false ;
135+ return false ;
136+ } catch ( e ) {
137+ console . warn ( 'Problems consuming cache' ) ;
138+ console . warn ( e ) ;
139+
140+ return false ;
141+ }
130142}
0 commit comments