summaryrefslogtreecommitdiff
path: root/candle-wasm-examples/whisper/whisperWorker.js
diff options
context:
space:
mode:
Diffstat (limited to 'candle-wasm-examples/whisper/whisperWorker.js')
-rw-r--r--candle-wasm-examples/whisper/whisperWorker.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/candle-wasm-examples/whisper/whisperWorker.js b/candle-wasm-examples/whisper/whisperWorker.js
index 2598adde..d2ad8e0b 100644
--- a/candle-wasm-examples/whisper/whisperWorker.js
+++ b/candle-wasm-examples/whisper/whisperWorker.js
@@ -2,16 +2,17 @@
import init, { Decoder } from "./build/m.js";
async function fetchArrayBuffer(url) {
- const res = await fetch(url, {
- cache: "force-cache",
- headers: {
- "Cache-Control": "public, max-age=31536000",
- },
- });
- const data = await res.arrayBuffer();
- return new Uint8Array(data);
+ const cacheName = "whisper-candle-cache";
+ const cache = await caches.open(cacheName);
+ const cachedResponse = await cache.match(url);
+ if (cachedResponse) {
+ const data = await cachedResponse.arrayBuffer();
+ return new Uint8Array(data);
+ }
+ const res = await fetch(url, { cache: "force-cache" });
+ cache.put(url, res.clone());
+ return new Uint8Array(await res.arrayBuffer());
}
-
class Whisper {
static instance = {};
// Retrieve the Whisper model. When called for the first time,