From 261c3996805bcdfb7ff271290f3e3557dd15cea7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 21 Feb 2026 16:59:31 +0900 Subject: feat(cache): add filesystem-backed cache with TTL expiration and size-limited GC Implement a cache module with CacheConfig and Cache structs supporting read/write (string and binary), atomic writes via temp+rename, TTL-based expiration, and size-limited garbage collection. Wire the repo cache into packagist.rs and resolver.rs for API response caching, and the files cache into downloader.rs for dist archive caching. Implement the clear-cache command with full clear and --gc modes. All existing call sites pass None for backward compatibility. Co-Authored-By: Claude Opus 4.6 --- crates/mozart/src/lockfile.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/mozart/src/lockfile.rs') diff --git a/crates/mozart/src/lockfile.rs b/crates/mozart/src/lockfile.rs index 7c945b8..4742772 100644 --- a/crates/mozart/src/lockfile.rs +++ b/crates/mozart/src/lockfile.rs @@ -1,3 +1,4 @@ +use crate::cache::Cache; use crate::package::{RawPackageData, to_json_pretty}; use crate::packagist::{self, PackagistDist, PackagistSource, PackagistVersion}; use crate::resolver::ResolvedPackage; @@ -241,6 +242,8 @@ pub struct LockFileGenerationRequest { pub composer_json: RawPackageData, /// Whether require-dev was included in resolution. pub include_dev: bool, + /// Optional repo cache for Packagist API calls made during generation. + pub repo_cache: Option, } /// Convert a `PackagistSource` to a `LockedSource`. @@ -393,7 +396,7 @@ pub fn generate_lock_file(request: &LockFileGenerationRequest) -> anyhow::Result // 1. Fetch full metadata for all resolved packages let mut package_metadata: HashMap = HashMap::new(); for pkg in &request.resolved_packages { - let versions = packagist::fetch_package_versions(&pkg.name)?; + let versions = packagist::fetch_package_versions(&pkg.name, request.repo_cache.as_ref())?; // Find the exact version matching pkg.version_normalized let matching = versions .into_iter() @@ -921,6 +924,7 @@ mod tests { composer_json_content: composer_json_content.clone(), composer_json, include_dev: true, + repo_cache: None, }; let lock = generate_lock_file(&request).unwrap(); @@ -1024,6 +1028,7 @@ mod tests { platform: PlatformConfig::new(), ignore_platform_reqs: false, ignore_platform_req_list: vec![], + repo_cache: None, }; let resolved = resolve(&resolve_request).expect("Resolution should succeed"); @@ -1038,6 +1043,7 @@ mod tests { composer_json_content: composer_json_content.clone(), composer_json, include_dev: false, + repo_cache: None, }; let lock = generate_lock_file(&gen_request).expect("Lock file generation should succeed"); -- cgit v1.3.1