aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart/src/lockfile.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-21 16:59:31 +0900
committernsfisis <nsfisis@gmail.com>2026-02-21 16:59:31 +0900
commit261c3996805bcdfb7ff271290f3e3557dd15cea7 (patch)
treecc701824713b792729bb29f40181698efc387104 /crates/mozart/src/lockfile.rs
parent3535037592f149477c915a8b66da974eb59586db (diff)
downloadphp-mozart-261c3996805bcdfb7ff271290f3e3557dd15cea7.tar.gz
php-mozart-261c3996805bcdfb7ff271290f3e3557dd15cea7.tar.zst
php-mozart-261c3996805bcdfb7ff271290f3e3557dd15cea7.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/lockfile.rs')
-rw-r--r--crates/mozart/src/lockfile.rs8
1 files changed, 7 insertions, 1 deletions
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<Cache>,
}
/// 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<String, PackagistVersion> = 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");