(config: &CacheManagerConfig)
| 356 | |
| 357 | impl CacheManager { |
| 358 | pub fn try_new(config: &CacheManagerConfig) -> Result<Arc<Self>> { |
| 359 | let file_statistic_cache = match &config.file_statistics_cache { |
| 360 | Some(fsc) if config.file_statistics_cache_limit > 0 => { |
| 361 | fsc.update_cache_limit(config.file_statistics_cache_limit); |
| 362 | Some(Arc::clone(fsc)) |
| 363 | } |
| 364 | None if config.file_statistics_cache_limit > 0 => { |
| 365 | let fsc: Arc<dyn FileStatisticsCache> = Arc::new( |
| 366 | DefaultFileStatisticsCache::new(config.file_statistics_cache_limit), |
| 367 | ); |
| 368 | Some(fsc) |
| 369 | } |
| 370 | _ => None, |
| 371 | }; |
| 372 | |
| 373 | let list_files_cache = match &config.list_files_cache { |
| 374 | Some(lfc) if config.list_files_cache_limit > 0 => { |
| 375 | // the cache memory limit or ttl might have changed, ensure they are updated |
| 376 | lfc.update_cache_limit(config.list_files_cache_limit); |
| 377 | // Only update TTL if explicitly set in config, otherwise preserve the cache's existing TTL |
| 378 | if let Some(ttl) = config.list_files_cache_ttl { |
| 379 | lfc.update_cache_ttl(Some(ttl)); |
| 380 | } |
| 381 | Some(Arc::clone(lfc)) |
| 382 | } |
| 383 | None if config.list_files_cache_limit > 0 => { |
| 384 | let lfc: Arc<dyn ListFilesCache> = Arc::new(DefaultListFilesCache::new( |
| 385 | config.list_files_cache_limit, |
| 386 | config.list_files_cache_ttl, |
| 387 | )); |
| 388 | Some(lfc) |
| 389 | } |
| 390 | _ => None, |
| 391 | }; |
| 392 | |
| 393 | let file_metadata_cache = config |
| 394 | .file_metadata_cache |
| 395 | .as_ref() |
| 396 | .map(Arc::clone) |
| 397 | .unwrap_or_else(|| { |
| 398 | Arc::new(DefaultFilesMetadataCache::new(config.metadata_cache_limit)) |
| 399 | }); |
| 400 | |
| 401 | // the cache memory limit might have changed, ensure the limit is updated |
| 402 | file_metadata_cache.update_cache_limit(config.metadata_cache_limit); |
| 403 | |
| 404 | Ok(Arc::new(CacheManager { |
| 405 | file_statistic_cache, |
| 406 | list_files_cache, |
| 407 | file_metadata_cache, |
| 408 | })) |
| 409 | } |
| 410 | |
| 411 | /// Get the file statistics cache. |
| 412 | pub fn get_file_statistic_cache(&self) -> Option<Arc<dyn FileStatisticsCache>> { |
nothing calls this directly
no test coverage detected