* Fetch NDArray cache from url. * * @param ndarrayCacheUrl The cache url. * @param device The device to be fetched to. * @returns The meta data
(ndarrayCacheUrl, device)
| 2396 | * @returns The meta data |
| 2397 | */ |
| 2398 | fetchNDArrayCache(ndarrayCacheUrl, device) { |
| 2399 | return __awaiter(this, void 0, void 0, function* () { |
| 2400 | const jsonUrl = new URL("ndarray-cache.json", ndarrayCacheUrl).href; |
| 2401 | const request = new Request(jsonUrl); |
| 2402 | const cache = yield caches.open("tvmjs"); |
| 2403 | let result = yield cache.match(request); |
| 2404 | if (result === undefined) { |
| 2405 | yield cache.add(request); |
| 2406 | result = yield cache.match(request); |
| 2407 | } |
| 2408 | if (result === undefined) { |
| 2409 | this.env.logger("Error: Cannot cache " + jsonUrl + ", reloading will be slow"); |
| 2410 | try { |
| 2411 | result = yield fetch(request); |
| 2412 | } catch (err) { |
| 2413 | this.env.logger("Cannot fetch " + jsonUrl); |
| 2414 | } |
| 2415 | } |
| 2416 | let list; |
| 2417 | if (result instanceof Response) { |
| 2418 | list = yield result.json(); |
| 2419 | } |
| 2420 | yield this.fetchNDArrayCacheInternal(ndarrayCacheUrl, list["records"], device); |
| 2421 | this.cacheMetadata = Object.assign(Object.assign({}, this.cacheMetadata), list["metadata"]); |
| 2422 | }); |
| 2423 | } |
| 2424 | /** |
| 2425 | * Fetch list of NDArray into the NDArrayCache. |
| 2426 | * |