Expand description
Content-addressed cache over backend rendering. Content-addressed render cache.
Caches backend rendering output keyed on the source IR’s content
hash and the backend’s platform identifier. A cache hit skips
the entire generate_resource call — rendering becomes a hashmap
lookup when nothing in the IR changed.
§Invariants
- Purity is required. Cache hits short-circuit
Backend::apply; if a backend has observable side effects (touching the filesystem, writing a log, reading env vars), the cache hides them. All existing backends are pure renderers — this is safe for them. - Schema version. The cache key includes a schema version so
Backend trait upgrades that change output invalidate old entries
automatically. Bump
SCHEMA_VERSIONwhenever the Backend contract changes in a user-visible way. - Deterministic inputs. Because
content_hashis over canonical emission and canonical emission is deterministic (proven by proptest), two semantically-equal IR values ALWAYS produce the same cache key.
§Usage
use iac_forge::render_cache::RenderCache;
let mut cache = RenderCache::new();
let artifacts = cache.render(backend, &input);
// Second call with the same (backend, input) is a lookup.
let artifacts2 = cache.render(backend, &input);Structs§
- Cache
Key - Cache key: (schema_version, backend_platform, ir_content_hash).
- Cache
Stats - A stat block for cache observability — useful in tests and telemetry.
- Render
Cache - In-memory render cache.
Constants§
- SCHEMA_
VERSION - Schema version embedded in every cache key. Bump when the Backend trait’s output contract changes in a way that would invalidate cached artifacts (new mandatory field, changed path scheme, etc.).