diff options
author | Satya Rohith <me@satyarohith.com> | 2022-09-28 17:41:12 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-28 17:41:12 +0530 |
commit | b312279e58e51520a38e51cca317a09cdadd7cb4 (patch) | |
tree | a0c6f432042ba25b569c151bbe59f1e721788d0c /runtime/worker.rs | |
parent | 1156f726a92d3d3985e591327c7526cd3e2b0473 (diff) |
feat: implement Web Cache API (#15829)
Diffstat (limited to 'runtime/worker.rs')
-rw-r--r-- | runtime/worker.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/runtime/worker.rs b/runtime/worker.rs index 0723cef84..3ac3654e2 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -7,6 +7,8 @@ use crate::ops::io::Stdio; use crate::permissions::Permissions; 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::Future; @@ -85,6 +87,7 @@ pub struct WorkerOptions { pub maybe_inspector_server: Option<Arc<InspectorServer>>, pub should_break_on_first_statement: bool, pub get_error_class_fn: Option<GetErrorClassFn>, + pub cache_storage_dir: Option<std::path::PathBuf>, pub origin_storage_dir: Option<std::path::PathBuf>, pub blob_store: BlobStore, pub broadcast_channel: InMemoryBroadcastChannel, @@ -131,6 +134,10 @@ impl MainWorker { }) .build(); let exit_code = ExitCode(Arc::new(AtomicI32::new(0))); + 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)) + }); // Internal modules let mut extensions: Vec<Extension> = vec![ @@ -151,6 +158,7 @@ impl MainWorker { 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(), @@ -527,6 +535,7 @@ mod tests { module_loader: Rc::new(deno_core::FsModuleLoader), npm_resolver: None, get_error_class_fn: None, + cache_storage_dir: None, origin_storage_dir: None, blob_store: BlobStore::default(), broadcast_channel: InMemoryBroadcastChannel::default(), |