0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-08 07:16:56 -05:00

caches: allow explicit in-memory caches

This commit is contained in:
Johannes Kirschbauer 2024-11-11 16:45:53 +01:00
parent bfc143a5ac
commit 08a5199bc3
No known key found for this signature in database
5 changed files with 34 additions and 4 deletions

View file

@ -597,6 +597,8 @@ pub struct Flags {
pub argv: Vec<String>, pub argv: Vec<String>,
pub subcommand: DenoSubcommand, pub subcommand: DenoSubcommand,
/// Flag
pub in_memory_cache: Option<bool>,
pub frozen_lockfile: Option<bool>, pub frozen_lockfile: Option<bool>,
pub ca_stores: Option<Vec<String>>, pub ca_stores: Option<Vec<String>>,
pub ca_data: Option<CaData>, pub ca_data: Option<CaData>,
@ -2821,6 +2823,7 @@ fn run_args(command: Command, top_level: bool) -> Command {
}) })
.arg(env_file_arg()) .arg(env_file_arg())
.arg(no_code_cache_arg()) .arg(no_code_cache_arg())
.arg(in_memory_cache_arg())
} }
fn run_subcommand() -> Command { fn run_subcommand() -> Command {
@ -3951,6 +3954,13 @@ fn no_clear_screen_arg() -> Arg {
.help_heading(FILE_WATCHING_HEADING) .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 { fn no_code_cache_arg() -> Arg {
Arg::new("no-code-cache") Arg::new("no-code-cache")
.long("no-code-cache") .long("no-code-cache")

View file

@ -1685,6 +1685,10 @@ impl CliOptions {
self.flags.code_cache_enabled 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<PathBuf> { pub fn watch_paths(&self) -> Vec<PathBuf> {
let mut full_paths = Vec::new(); let mut full_paths = Vec::new();
if let DenoSubcommand::Run(RunFlags { if let DenoSubcommand::Run(RunFlags {

17
cli/cache/caches.rs vendored
View file

@ -16,6 +16,7 @@ use super::module_info::MODULE_INFO_CACHE_DB;
use super::node::NODE_ANALYSIS_CACHE_DB; use super::node::NODE_ANALYSIS_CACHE_DB;
pub struct Caches { pub struct Caches {
in_memory: bool,
dir_provider: Arc<DenoDirProvider>, dir_provider: Arc<DenoDirProvider>,
fmt_incremental_cache_db: OnceCell<CacheDB>, fmt_incremental_cache_db: OnceCell<CacheDB>,
lint_incremental_cache_db: OnceCell<CacheDB>, lint_incremental_cache_db: OnceCell<CacheDB>,
@ -27,8 +28,9 @@ pub struct Caches {
} }
impl Caches { impl Caches {
pub fn new(dir: Arc<DenoDirProvider>) -> Self { pub fn new(dir: Arc<DenoDirProvider>, in_memory: bool) -> Self {
Self { Self {
in_memory,
dir_provider: dir, dir_provider: dir,
fmt_incremental_cache_db: Default::default(), fmt_incremental_cache_db: Default::default(),
lint_incremental_cache_db: Default::default(), lint_incremental_cache_db: Default::default(),
@ -41,13 +43,17 @@ impl Caches {
} }
fn make_db( fn make_db(
&self,
cell: &OnceCell<CacheDB>, cell: &OnceCell<CacheDB>,
config: &'static CacheDBConfiguration, config: &'static CacheDBConfiguration,
path: Option<PathBuf>, path: Option<PathBuf>,
) -> CacheDB { ) -> CacheDB {
cell cell
.get_or_init(|| { .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( CacheDB::from_path(
config, config,
path, path,
@ -62,6 +68,7 @@ impl Caches {
pub fn fmt_incremental_cache_db(&self) -> CacheDB { pub fn fmt_incremental_cache_db(&self) -> CacheDB {
Self::make_db( Self::make_db(
self,
&self.fmt_incremental_cache_db, &self.fmt_incremental_cache_db,
&INCREMENTAL_CACHE_DB, &INCREMENTAL_CACHE_DB,
self self
@ -74,6 +81,7 @@ impl Caches {
pub fn lint_incremental_cache_db(&self) -> CacheDB { pub fn lint_incremental_cache_db(&self) -> CacheDB {
Self::make_db( Self::make_db(
self,
&self.lint_incremental_cache_db, &self.lint_incremental_cache_db,
&INCREMENTAL_CACHE_DB, &INCREMENTAL_CACHE_DB,
self self
@ -86,6 +94,7 @@ impl Caches {
pub fn dep_analysis_db(&self) -> CacheDB { pub fn dep_analysis_db(&self) -> CacheDB {
Self::make_db( Self::make_db(
self,
&self.dep_analysis_db, &self.dep_analysis_db,
&MODULE_INFO_CACHE_DB, &MODULE_INFO_CACHE_DB,
self self
@ -98,6 +107,7 @@ impl Caches {
pub fn fast_check_db(&self) -> CacheDB { pub fn fast_check_db(&self) -> CacheDB {
Self::make_db( Self::make_db(
self,
&self.fast_check_db, &self.fast_check_db,
&FAST_CHECK_CACHE_DB, &FAST_CHECK_CACHE_DB,
self self
@ -110,6 +120,7 @@ impl Caches {
pub fn node_analysis_db(&self) -> CacheDB { pub fn node_analysis_db(&self) -> CacheDB {
Self::make_db( Self::make_db(
self,
&self.node_analysis_db, &self.node_analysis_db,
&NODE_ANALYSIS_CACHE_DB, &NODE_ANALYSIS_CACHE_DB,
self self
@ -122,6 +133,7 @@ impl Caches {
pub fn type_checking_cache_db(&self) -> CacheDB { pub fn type_checking_cache_db(&self) -> CacheDB {
Self::make_db( Self::make_db(
self,
&self.type_checking_cache_db, &self.type_checking_cache_db,
&TYPE_CHECK_CACHE_DB, &TYPE_CHECK_CACHE_DB,
self self
@ -134,6 +146,7 @@ impl Caches {
pub fn code_cache_db(&self) -> CacheDB { pub fn code_cache_db(&self) -> CacheDB {
Self::make_db( Self::make_db(
self,
&self.code_cache_db, &self.code_cache_db,
&CODE_CACHE_DB, &CODE_CACHE_DB,
self self

View file

@ -265,7 +265,10 @@ impl CliFactory {
pub fn caches(&self) -> Result<&Arc<Caches>, AnyError> { pub fn caches(&self) -> Result<&Arc<Caches>, AnyError> {
self.services.caches.get_or_try_init(|| { self.services.caches.get_or_try_init(|| {
let cli_options = self.cli_options()?; 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 // Warm up the caches we know we'll likely need based on the CLI mode
match cli_options.sub_command() { match cli_options.sub_command() {
DenoSubcommand::Run(_) DenoSubcommand::Run(_)

View file

@ -632,7 +632,7 @@ pub async fn run(data: StandaloneData) -> Result<i32, AnyError> {
unstable_detect_cjs: metadata.unstable_config.detect_cjs, 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 node_analysis_cache = NodeAnalysisCache::new(cache_db.node_analysis_db());
let cli_node_resolver = Arc::new(CliNodeResolver::new( let cli_node_resolver = Arc::new(CliNodeResolver::new(
cjs_tracker.clone(), cjs_tracker.clone(),