Spaces:
Running
Running
force caching using cache api (#3)
Browse files- force caching using cache api (10b31f1be76717a561b2122713fda6409495c7e9)
Co-authored-by: Radamés Ajna <radames@users.noreply.huggingface.co>
- 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
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
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,
|