1#![allow(clippy::missing_errors_doc)] pub mod kv;
10mod rust_plan;
11mod store;
12
13pub use kv::{
14 is_valid_namespace, Key, KvError, KvResult, KvStore, INLINE_THRESHOLD, MAX_VALUE_BYTES,
15};
16pub use rust_plan::{
17 restore_rust_plan_local, rust_plan_bundle_dir, rust_plan_cache_key, save_rust_plan_local,
18 RustArtifactBundleManifest, RustArtifactClass, RustArtifactPlanV1, RustBundledArtifact,
19 RustPlanArtifactEffectiveness, RustPlanCompatibility, RustPlanError, RustPlanInputs,
20 RustPlanMode, RustPlanOperation, RustPlanPackages, RustPlanSkippedSample, RustPlanSummary,
21 RustToolchainIdentity, RUST_ARTIFACT_CACHE_SCHEMA_VERSION, RUST_ARTIFACT_PLAN_SCHEMA_VERSION,
22};
23pub use store::{ArtifactIndex, ArtifactStore};
24
25use std::path::Path;
26use zccache_core::NormalizedPath;
27
28#[derive(Debug, Clone)]
30pub struct ArtifactStoreConfig {
31 pub cache_dir: NormalizedPath,
33 pub max_size: u64,
35}
36
37pub struct ArtifactStoreLegacy {
45 config: ArtifactStoreConfig,
46}
47
48impl ArtifactStoreLegacy {
49 pub fn open(config: ArtifactStoreConfig) -> zccache_core::Result<Self> {
53 std::fs::create_dir_all(&config.cache_dir)?;
54 Ok(Self { config })
55 }
56
57 #[must_use]
59 pub fn artifact_path(&self, key: &zccache_hash::ContentHash) -> NormalizedPath {
60 let shards = key.shard_prefix(2, 1);
61 self.config
62 .cache_dir
63 .join("artifacts")
64 .join(&shards[0])
65 .join(&shards[1])
66 .join(key.to_hex())
67 }
68
69 #[must_use]
71 pub fn contains(&self, key: &zccache_hash::ContentHash) -> bool {
72 self.artifact_path(key).exists()
73 }
74
75 #[must_use]
77 pub fn cache_dir(&self) -> &Path {
78 &self.config.cache_dir
79 }
80}