diff --git a/eden/scm/lib/cas-client/rich-client/src/lib.rs b/eden/scm/lib/cas-client/rich-client/src/lib.rs index d28424c49da41..1ff7f32e6c5b8 100644 --- a/eden/scm/lib/cas-client/rich-client/src/lib.rs +++ b/eden/scm/lib/cas-client/rich-client/src/lib.rs @@ -45,6 +45,8 @@ pub struct RichCasClient { fetch_limit: ByteCount, fetch_concurrency: usize, use_streaming_dowloads: bool, + private_cache_path: Option, + private_cache_size: ByteCount, } pub fn init() { @@ -96,6 +98,16 @@ impl RichCasClient { let default_fetch_limit = ByteCount::try_from_str("200MB")?; + let private_cache_path = config.get_opt::("cas", "private-cache-path")?; + if private_cache_path.is_some() && use_casd_cache { + return Err(anyhow::anyhow!( + "cas.private-cache-path and cas.use-shared-cache cannot be used together" + )); + } + let default_private_cache_size = ByteCount::try_from_str("100GB")?; + let private_cache_size = config + .get_or::("cas", "private-cache-size", || default_private_cache_size)?; + Ok(Some(Self { client: Default::default(), verbose: config.get_or_default("cas", "verbose")?, @@ -109,6 +121,8 @@ impl RichCasClient { .get_or::("cas", "max-batch-bytes", || default_fetch_limit)?, fetch_concurrency: config.get_or("cas", "fetch-concurrency", || 4)?, use_streaming_dowloads: config.get_or("cas", "use-streaming-downloads", || true)?, + private_cache_path, + private_cache_size, })) } @@ -154,6 +168,17 @@ impl RichCasClient { embedded_config.remote_cache_config = Some(remote_cache_config); embedded_config.cache_config.writable_cache = false; } + // We check that the modes use_casd_cache and private_cache_path do not conflict while parcing the sapling config. + // So, if we are here, we know that the private cache is enabled. + if let Some(ref private_cache_path) = self.private_cache_path { + embedded_config.cache_config.downloads_cache_config.dir_path = + Some(private_cache_path.clone()); + embedded_config + .cache_config + .downloads_cache_config + .size_bytes = self.private_cache_size.value() as i64; + embedded_config.cache_config.writable_cache = true; + } re_config.cas_client_config = CASDaemonClientCfg::embedded_config(embedded_config); let builder = REClientBuilder::new(fbinit::expect_init())