diff options
Diffstat (limited to 'candle-wasm-examples/llama2-c/llama2cWorker.js')
-rw-r--r-- | candle-wasm-examples/llama2-c/llama2cWorker.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/candle-wasm-examples/llama2-c/llama2cWorker.js b/candle-wasm-examples/llama2-c/llama2cWorker.js index e4229055..abaf3401 100644 --- a/candle-wasm-examples/llama2-c/llama2cWorker.js +++ b/candle-wasm-examples/llama2-c/llama2cWorker.js @@ -1,13 +1,17 @@ import init, { Model } from "./build/m.js"; async function fetchArrayBuffer(url) { - const res = await fetch(url, { - cache: "force-cache", - }); - const data = await res.arrayBuffer(); - return new Uint8Array(data); + const cacheName = "llama2c-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 Llama2C { static instance = {}; |