This policy defines a deterministic, stable mechanism for generating build cache keys in CI/CD pipelines (e.g., for tools like Nix, Bazel, Earthly, or custom Docker layer caching). The goal is cache stability: identical inputs always produce the same key (hits), and any relevant change produces a different key (misses). Keys are stateless, normalized, and hashed for immutability.
1. Inputs
Cache keys are derived only from these canonical inputs, categorized by type. No runtime state (e.g., timestamps, machine IDs, or transient env vars) is included.
Primary Inputs (Always Included)
Category
Examples
Rationale
Normalization
Source Code
Git commit SHA, or recursive hash of src/ files (exclude .git/)
All inputs are transformed via pure functions (no side effects, I/O, or state). Rules ensure commutativity (order-independent) and consistency across runs/machines.
Core Rules
Sorting: Lists/objects sorted lexicographically (e.g., env vars by key).
Canonicalization:
Strings: Lowercase, trim whitespace, UTF-8 normalize (NFKC).
Paths: Absolute, forward slashes (/), no trailing /.
Numbers: Stringify without scientific notation.
Ignore Irrelevant Changes:
Whitespace/comments: Strip via sed -E 's/[[:space:]]+//g; s#//.*$##; s#/\*.*\*/##g'.