This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/unity by this push:
new 84e286be71 [Unity] Cache ndarray-cache.json (#14722)
84e286be71 is described below
commit 84e286be7194456d7d4f2d384f790e9f731b5da3
Author: Dustin Brett <[email protected]>
AuthorDate: Wed Apr 26 06:47:07 2023 -0700
[Unity] Cache ndarray-cache.json (#14722)
Cache ndarray-cache.json also
---
web/src/runtime.ts | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/web/src/runtime.ts b/web/src/runtime.ts
index 3b77aba88f..fbceed1df9 100644
--- a/web/src/runtime.ts
+++ b/web/src/runtime.ts
@@ -1372,11 +1372,24 @@ export class Instance implements Disposable {
*/
async fetchNDArrayCache(ndarrayCacheUrl: string, device: DLDevice) :
Promise<any> {
const jsonUrl = new URL("ndarray-cache.json", ndarrayCacheUrl).href;
- var list;
- try {
- list = await (await fetch(jsonUrl)).json();
- } catch(err) {
- this.env.logger("Cannot fetch " + jsonUrl);
+ const request = new Request(jsonUrl);
+ const cache = await caches.open("tvmjs");
+ let result = await cache.match(request);
+ if (result === undefined) {
+ await cache.add(request);
+ result = await cache.match(request);
+ }
+ if (result === undefined) {
+ this.env.logger("Error: Cannot cache " + jsonUrl + ", reloading will be
slow");
+ try {
+ result = await fetch(request);
+ } catch(err) {
+ this.env.logger("Cannot fetch " + jsonUrl);
+ }
+ }
+ let list;
+ if (result instanceof Response) {
+ list = await result.json();
}
await this.fetchNDArrayCacheInternal(
ndarrayCacheUrl,