pub struct ArtifactCachePrunePolicy { /* private fields */ }Expand description
Caller-selected retention limits for content-addressed artifact entries.
Age pruning runs before size pruning. A policy without either limit scans the selected cache namespace and updates its cache metadata without removing entries. Entries retained by live acquisition records are skipped, even when this temporarily exceeds the limits. They become eligible for the next maintenance pass after their final owner drops or its process exits.
Implementations§
Source§impl ArtifactCachePrunePolicy
impl ArtifactCachePrunePolicy
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a policy that records cache metadata without removing entries.
Examples found in repository?
examples/transactional_artifact_cache.rs (line 63)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub const fn with_max_age(self, max_age: Duration) -> Self
pub const fn with_max_age(self, max_age: Duration) -> Self
Remove entries older than max_age before applying the size limit.
Examples found in repository?
examples/transactional_artifact_cache.rs (line 64)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub const fn with_max_size_bytes(self, bytes: u64) -> Self
pub const fn with_max_size_bytes(self, bytes: u64) -> Self
Remove least-recently-used entries until retained logical size is at most bytes.
Examples found in repository?
examples/transactional_artifact_cache.rs (line 65)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub const fn max_size_bytes(self) -> Option<u64>
pub const fn max_size_bytes(self) -> Option<u64>
Configured maximum logical cache size in bytes, if any.
Trait Implementations§
Source§impl Clone for ArtifactCachePrunePolicy
impl Clone for ArtifactCachePrunePolicy
impl Copy for ArtifactCachePrunePolicy
Source§impl Debug for ArtifactCachePrunePolicy
impl Debug for ArtifactCachePrunePolicy
Source§impl Default for ArtifactCachePrunePolicy
impl Default for ArtifactCachePrunePolicy
impl Eq for ArtifactCachePrunePolicy
Source§impl PartialEq for ArtifactCachePrunePolicy
impl PartialEq for ArtifactCachePrunePolicy
impl StructuralPartialEq for ArtifactCachePrunePolicy
Auto Trait Implementations§
impl Freeze for ArtifactCachePrunePolicy
impl RefUnwindSafe for ArtifactCachePrunePolicy
impl Send for ArtifactCachePrunePolicy
impl Sync for ArtifactCachePrunePolicy
impl Unpin for ArtifactCachePrunePolicy
impl UnsafeUnpin for ArtifactCachePrunePolicy
impl UnwindSafe for ArtifactCachePrunePolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more