Skip to main content

Module cache

Module cache 

Source
Expand description

Binary scene cache: TOML stays source of truth; _cache/ holds content-hash-keyed, version-stamped binaries.

Pure logic lives here (hash, paths, encode/decode, stale matching); lib.rs owns the filesystem flow (load_cached).

Structs§

CacheHeader
Header carried by every cache file: which container and scene versions it was written with, plus the exact source it came from.

Enums§

CacheStatus
How a scene load resolved: cache hit, clean miss (no usable cache), or rebuild (cache existed but was stale/corrupt/mismatched).

Constants§

CACHE_DIR_NAME
Sibling directory next to each scene file holding its binaries.
CACHE_EXT
Extension for cache files: <stem>.<content-hash>.bin.
CACHE_VERSION
Cache container version. A bump rebuilds every cache from TOML instead of misreading it.

Functions§

cache_path_for
Cache path for a scene file + hex content hash: <scene_dir>/_cache/<stem>.<hash>.bin. The hash keys the cache, so any source change is a different file (old ones get pruned).
content_hash
Lowercase hex content hash used in cache filenames.
decode
Decode a cache payload. Bad magic, truncation, trailing bytes, or a version stamp that is not the live one all fail loudly — the caller falls back to TOML and says so, never silently reinterprets.
encode
Encode a scene document as a cache payload stamped with the live CACHE_VERSION and FORMAT_VERSION.
encode_with
Encode with explicit stamps (test hook: simulates version bumps without touching the live constants).
fnv1a_u64
FNV-1a 64-bit over bytes (same function as pite-assets, zero deps).
prune_stale
Remove sibling caches for scene_path whose hash differs from keep_hash_hex; returns removed paths. Best-effort: unreadable dirs or failed removals are ignored, never errors.