lmz radames commited on
Commit
7c6fd42
1 Parent(s): e521042

force caching using cache api (#3)

Browse files

- force caching using cache api (10b31f1be76717a561b2122713fda6409495c7e9)


Co-authored-by: Radamés Ajna <[email protected]>

Files changed (1) hide show
  1. whisperWorker.js +10 -9
whisperWorker.js CHANGED
@@ -2,16 +2,17 @@
2
  import init, { Decoder } from "./build/m.js";
3
 
4
  async function fetchArrayBuffer(url) {
5
- const res = await fetch(url, {
6
- cache: "force-cache",
7
- headers: {
8
- "Cache-Control": "public, max-age=31536000",
9
- },
10
- });
11
- const data = await res.arrayBuffer();
12
- return new Uint8Array(data);
 
 
13
  }
14
-
15
  class Whisper {
16
  static instance = {};
17
  // Retrieve the Whisper model. When called for the first time,
 
2
  import init, { Decoder } from "./build/m.js";
3
 
4
  async function fetchArrayBuffer(url) {
5
+ const cacheName = "whisper-candle-cache";
6
+ const cache = await caches.open(cacheName);
7
+ const cachedResponse = await cache.match(url);
8
+ if (cachedResponse) {
9
+ const data = await cachedResponse.arrayBuffer();
10
+ return new Uint8Array(data);
11
+ }
12
+ const res = await fetch(url, { cache: "force-cache" });
13
+ cache.put(url, res.clone());
14
+ return new Uint8Array(await res.arrayBuffer());
15
  }
 
16
  class Whisper {
17
  static instance = {};
18
  // Retrieve the Whisper model. When called for the first time,