An agent runs across multiple sequential workflow jobs and needs to preserve intermediate results (such as parsed dependency graphs) between jobs without re-computing them. The data is only relevant for the current feature branch and does not need to persist beyond a week. Which GitHub mechanism is best suited for this use case?
Select an answer to reveal the explanation.
Short Explanation and Infographic
The Actions cache is the agent's notebook between class periods — it stores what was learned (the parsed dependency graph) so the next job does not re-read the whole textbook. It is branch-scoped and auto-expires, making it perfect for intermediate per-branch computation.
Full explanation below image
Full Explanation
The GitHub Actions cache (actions/cache) is designed exactly for this use case: storing intermediate computation results that should be reused across jobs or workflow runs on the same branch. Keying the cache by branch name and a hash of the relevant input (e.g., the lockfile hash) ensures the cache is invalidated when the underlying data changes. The cache auto-expires after a configurable period (default 7 days of inactivity), which matches the stated retention requirement.
Option A (workflow artifact with 7-day retention) would also work but artifacts are better suited for final outputs and cross-run audit data, not intermediate computation caches. Artifacts do not support cache-style invalidation based on content hashes, and they accumulate on every run rather than being overwritten when fresh data is available.
Option C (commit to a cache branch) is an anti-pattern: it pollutes the repository history with machine-generated data, creates write contention when multiple workflow runs occur simultaneously, and makes the data permanent unless explicitly cleaned up.
Option D (repository variable via API) is limited in size (typically a few KB), not designed for arbitrary structured data, and updating it requires API calls with appropriate permissions that may not be configured for the workflow.
The Actions cache with a branch-and-content-hash cache key is the correct, purpose-built mechanism for inter-job short-term agent memory.