summaryrefslogtreecommitdiff
path: root/runtime/web_worker.rs
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2022-09-28 17:41:12 +0530
committerGitHub <noreply@github.com>2022-09-28 17:41:12 +0530
commitb312279e58e51520a38e51cca317a09cdadd7cb4 (patch)
treea0c6f432042ba25b569c151bbe59f1e721788d0c /runtime/web_worker.rs
parent1156f726a92d3d3985e591327c7526cd3e2b0473 (diff)
feat: implement Web Cache API (#15829)
Diffstat (limited to 'runtime/web_worker.rs')
-rw-r--r--runtime/web_worker.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index 306e1da5c..09a631916 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -9,6 +9,8 @@ use crate::tokio_util::run_local;
use crate::worker::FormatJsErrorFn;
use crate::BootstrapOptions;
use deno_broadcast_channel::InMemoryBroadcastChannel;
+use deno_cache::CreateCache;
+use deno_cache::SqliteBackedCache;
use deno_core::error::AnyError;
use deno_core::error::JsError;
use deno_core::futures::channel::mpsc;
@@ -337,6 +339,7 @@ pub struct WebWorkerOptions {
pub broadcast_channel: InMemoryBroadcastChannel,
pub shared_array_buffer_store: Option<SharedArrayBufferStore>,
pub compiled_wasm_module_store: Option<CompiledWasmModuleStore>,
+ pub cache_storage_dir: Option<std::path::PathBuf>,
pub stdio: Stdio,
}
@@ -373,6 +376,10 @@ impl WebWorker {
Ok(())
})
.build();
+ let create_cache = options.cache_storage_dir.map(|storage_dir| {
+ let create_cache_fn = move || SqliteBackedCache::new(storage_dir.clone());
+ CreateCache(Arc::new(create_cache_fn))
+ });
let mut extensions: Vec<Extension> = vec![
// Web APIs
@@ -392,6 +399,7 @@ impl WebWorker {
file_fetch_handler: Rc::new(deno_fetch::FsFetchHandler),
..Default::default()
}),
+ deno_cache::init::<SqliteBackedCache>(create_cache),
deno_websocket::init::<Permissions>(
options.bootstrap.user_agent.clone(),
options.root_cert_store.clone(),