Skip to main content

consortium/dag/
cache.rs

1//! Cache strategy trait for skipping already-completed tasks.
2
3use std::any::Any;
4
5use crate::dag::context::DagContext;
6use crate::dag::types::TaskId;
7
8/// Trait for determining whether a task can be skipped.
9///
10/// Implementors check external state (nix store, file system, etc.)
11/// and return the cached output if available.
12pub trait CacheStrategy: Send + Sync + 'static {
13    /// Check if the task's output already exists.
14    /// Returns `Some(output)` if cached (task will be skipped),
15    /// `None` if the task must execute.
16    fn check(&self, task_id: &TaskId, ctx: &DagContext) -> Option<Box<dyn Any + Send>>;
17}
18
19/// Never cache — always execute tasks.
20pub struct NoCache;
21
22impl CacheStrategy for NoCache {
23    fn check(&self, _task_id: &TaskId, _ctx: &DagContext) -> Option<Box<dyn Any + Send>> {
24        None
25    }
26}