Module cache
Expand description
Persistent fact-store cache: key derivation + XDG path resolution.
Cache path layout:
$XDG_CACHE_HOME/codelore/<repo_hash_8>/<cache_key_16>.duckdb
Cache key covers: canonical_repo_path, HEAD SHA, crate version, options
thresholds, cache epoch. Excludes: rows_limit, repo_path (repository
identity is established by the canonical path hashed as the key’s first
component, so the raw spelling must not enter the options hash), cosmetic
flags.
Constants§
- CACHE_
EPOCH - Cache-invalidation epoch — a manual cache-buster folded into the cache
key. Bump on any correctness fix that should orphan existing cache files,
whether or not the
DuckDBschema shape changed. This is deliberately independent offacts::schema::CURRENT_SCHEMA_VERSION(the on-disk schema version): a non-schema correctness fix bumps this without touching the schema version, and the historicalschema_vprefix on the value is retained so older cache files stay invalidated. - GLOBAL_
CACHE_ MAX_ BYTES - Ceiling on total
.duckdbbytes across every repository’s cache. Companion.walfiles and the JSON sidecars are outside this total — only the fact stores are counted and evicted. - MAX_
REPO_ CACHE_ ENTRIES - Cache entries kept per repository before the oldest are evicted. Named
so the eviction bound and the number
codelore profilereports to the user come from one place.
Functions§
- cache_
key - Compute a 32-byte SHA-256 cache key from:
canonical_repo_path || NUL || head_sha || NUL || CARGO_PKG_VERSION || NUL|| opts_hash(opts) || NUL || CACHE_EPOCH - cache_
path - Resolve the on-disk path for a cache entry:
<cache_root>/codelore/<repo_hash_8>/<cache_key_16>.duckdb - cache_
path_ with_ root - Same as
cache_pathbut with an explicit root (for--cache-diroverride). - cached_
bytes - Total bytes of cached fact stores under
root, on the same basisprune_global_cacheevicts against, so a reported size and the cap it is reported against always measure the same thing. - cleanup_
stale_ tmp_ files - Remove
.tmp.<pid>and.tmp.<pid>.walartifacts indirthat are older than [STALE_TMP_AGE_SECS]. These are left behind by crashed ingest runs (the normal-path rename + drop sequence cleans them up). - default_
cache_ root - Return
dirs::cache_dir()or fall back to a user-namespaced subdir of/tmpwhen the XDG dirs are unavailable (headless CI, containers, etc.). - prune_
global_ cache - Walk
root/codelore/and delete.duckdbfiles (oldest first) until the total directory size falls belowmax_bytes. Also sweeps stale.tmp.<pid>artifacts across the global cache tree. - prune_
repo_ cache - Remove
.duckdbfiles fromrepo_dirbeyondmax_entries, deleting the oldest (by mtime) first. Also sweeps stale.tmp.<pid>and.tmp.<pid>.walartifacts left behind by crashed runs. - repo_
cache_ dir - Compute the per-repo cache subdirectory:
<cache_root>/codelore/<repo_hash_8>/