| 173 | }; |
| 174 | |
| 175 | const restoreFileFromSWCache = async () => { |
| 176 | try { |
| 177 | performance.mark('start-sw-cache-restore'); |
| 178 | const modelCache = await caches.open('models'); |
| 179 | const response = await modelCache.match('model.bin'); |
| 180 | if (!response) { |
| 181 | throw new Error(`File model.bin not found in sw-cache.`); |
| 182 | } |
| 183 | const file = await response.blob(); |
| 184 | performance.mark('end-sw-cache-restore'); |
| 185 | const mark = performance.measure( |
| 186 | 'sw-cache-restore', |
| 187 | 'start-sw-cache-restore', |
| 188 | 'end-sw-cache-restore' |
| 189 | ); |
| 190 | console.log( |
| 191 | 'Cached model file found in sw-cache.', |
| 192 | mark.name, |
| 193 | mark.duration.toFixed(2) |
| 194 | ); |
| 195 | modelBlobURL = URL.createObjectURL(file); |
| 196 | return 'Service Worker Cache'; |
| 197 | } catch (err) { |
| 198 | throw err; |
| 199 | } |
| 200 | }; |
| 201 | |
| 202 | const restoreFileFromFileHandle = async () => { |
| 203 | try { |