diff --git a/cli/args/flags.rs b/cli/args/flags.rs index eb77971748a335..0c299d91c391ae 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -597,6 +597,8 @@ pub struct Flags { pub argv: Vec, pub subcommand: DenoSubcommand, + /// Flag + pub in_memory_cache: Option, pub frozen_lockfile: Option, pub ca_stores: Option>, pub ca_data: Option, @@ -2821,6 +2823,7 @@ fn run_args(command: Command, top_level: bool) -> Command { }) .arg(env_file_arg()) .arg(no_code_cache_arg()) + .arg(in_memory_cache_arg()) } fn run_subcommand() -> Command { @@ -3951,6 +3954,13 @@ fn no_clear_screen_arg() -> Arg { .help_heading(FILE_WATCHING_HEADING) } +fn in_memory_cache_arg() -> Arg { + Arg::new("in_memory_cache") + .long("in-memory-cache") + .help("Disable all filesystem caches and use in-memory cache only") + .action(ArgAction::SetTrue) +} + fn no_code_cache_arg() -> Arg { Arg::new("no-code-cache") .long("no-code-cache") diff --git a/cli/args/mod.rs b/cli/args/mod.rs index e19025f8b10cb6..8a574a74ed8d68 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1685,6 +1685,10 @@ impl CliOptions { self.flags.code_cache_enabled } + pub fn in_memory_cache(&self) -> bool { + self.flags.in_memory_cache.unwrap_or(false) + } + pub fn watch_paths(&self) -> Vec { let mut full_paths = Vec::new(); if let DenoSubcommand::Run(RunFlags { diff --git a/cli/cache/caches.rs b/cli/cache/caches.rs index 54371cee48bf1f..c433221b175537 100644 --- a/cli/cache/caches.rs +++ b/cli/cache/caches.rs @@ -16,6 +16,7 @@ use super::module_info::MODULE_INFO_CACHE_DB; use super::node::NODE_ANALYSIS_CACHE_DB; pub struct Caches { + in_memory: bool, dir_provider: Arc, fmt_incremental_cache_db: OnceCell, lint_incremental_cache_db: OnceCell, @@ -27,8 +28,9 @@ pub struct Caches { } impl Caches { - pub fn new(dir: Arc) -> Self { + pub fn new(dir: Arc, in_memory: bool) -> Self { Self { + in_memory, dir_provider: dir, fmt_incremental_cache_db: Default::default(), lint_incremental_cache_db: Default::default(), @@ -41,13 +43,17 @@ impl Caches { } fn make_db( + &self, cell: &OnceCell, config: &'static CacheDBConfiguration, path: Option, ) -> CacheDB { cell .get_or_init(|| { - if let Some(path) = path { + // Return in memory cache if in_memory is true + if self.in_memory { + CacheDB::in_memory(config, crate::version::DENO_VERSION_INFO.deno) + } else if let Some(path) = path { CacheDB::from_path( config, path, @@ -62,6 +68,7 @@ impl Caches { pub fn fmt_incremental_cache_db(&self) -> CacheDB { Self::make_db( + self, &self.fmt_incremental_cache_db, &INCREMENTAL_CACHE_DB, self @@ -74,6 +81,7 @@ impl Caches { pub fn lint_incremental_cache_db(&self) -> CacheDB { Self::make_db( + self, &self.lint_incremental_cache_db, &INCREMENTAL_CACHE_DB, self @@ -86,6 +94,7 @@ impl Caches { pub fn dep_analysis_db(&self) -> CacheDB { Self::make_db( + self, &self.dep_analysis_db, &MODULE_INFO_CACHE_DB, self @@ -98,6 +107,7 @@ impl Caches { pub fn fast_check_db(&self) -> CacheDB { Self::make_db( + self, &self.fast_check_db, &FAST_CHECK_CACHE_DB, self @@ -110,6 +120,7 @@ impl Caches { pub fn node_analysis_db(&self) -> CacheDB { Self::make_db( + self, &self.node_analysis_db, &NODE_ANALYSIS_CACHE_DB, self @@ -122,6 +133,7 @@ impl Caches { pub fn type_checking_cache_db(&self) -> CacheDB { Self::make_db( + self, &self.type_checking_cache_db, &TYPE_CHECK_CACHE_DB, self @@ -134,6 +146,7 @@ impl Caches { pub fn code_cache_db(&self) -> CacheDB { Self::make_db( + self, &self.code_cache_db, &CODE_CACHE_DB, self diff --git a/cli/factory.rs b/cli/factory.rs index 4a36c75ba2af12..635821be50fa34 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -265,7 +265,10 @@ impl CliFactory { pub fn caches(&self) -> Result<&Arc, AnyError> { self.services.caches.get_or_try_init(|| { let cli_options = self.cli_options()?; - let caches = Arc::new(Caches::new(self.deno_dir_provider()?.clone())); + let caches = Arc::new(Caches::new( + self.deno_dir_provider()?.clone(), + cli_options.in_memory_cache(), + )); // Warm up the caches we know we'll likely need based on the CLI mode match cli_options.sub_command() { DenoSubcommand::Run(_) diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 85610f4c20f1f7..4d7a0ecc4c20ff 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -632,7 +632,7 @@ pub async fn run(data: StandaloneData) -> Result { unstable_detect_cjs: metadata.unstable_config.detect_cjs, }, )); - let cache_db = Caches::new(deno_dir_provider.clone()); + let cache_db = Caches::new(deno_dir_provider.clone(), false); let node_analysis_cache = NodeAnalysisCache::new(cache_db.node_analysis_db()); let cli_node_resolver = Arc::new(CliNodeResolver::new( cjs_tracker.clone(),