Skip to main content

Module cache

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 (already folded into repo_hash_8), cosmetic flags.

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_path but with an explicit root (for --cache-dir override).
cleanup_stale_tmp_files
Remove .tmp.<pid> and .tmp.<pid>.wal artifacts in dir that 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 /tmp when the XDG dirs are unavailable (headless CI, containers, etc.).
prune_global_cache
Walk root/codelore/ and delete .duckdb files (oldest first) until the total directory size falls below max_bytes. Also sweeps stale .tmp.<pid> artifacts across the global cache tree.
prune_repo_cache
Remove .duckdb files from repo_dir beyond max_entries, deleting the oldest (by mtime) first. Also sweeps stale .tmp.<pid> and .tmp.<pid>.wal artifacts left behind by crashed runs.
repo_cache_dir
Compute the per-repo cache subdirectory: <cache_root>/codelore/<repo_hash_8>/