Skip to content

The cache manager

A node that runs the same projects repeatedly would fetch the same artifacts over and over without somewhere to keep what it has already verified. It keeps three stores: the cache manager, an in-memory index of what the node has verified; the artifact file cache, which holds run route artifacts by digest; and the closure content store, which holds opened closure artifacts. This page covers what each store holds, its limits and lifetime, and the metrics the cache manager reports in every heartbeat.

The three stores

flowchart TB
  subgraph PROC["XRATUD PROCESS MEMORY"]
    direction LR
    A[("artifact namespace<br/>digest to local path")]
    E[("env namespace<br/>manifest to resolver fingerprint")]
    M[("model namespace<br/>project, binding, model")]
  end
  subgraph TMP["NODE-LOCAL STORAGE"]
    direction LR
    subgraph AFC["xratud_artifact_cache"]
      direction TB
      F[("sha256/ab/cdef.../artifact.bin")]
    end
    subgraph CS["xratud_runtime_closure_content_dataplane"]
      direction TB
      EN[("entries/<br/>metadata per content digest")]
      BL[("blobs/<br/>fetched bytes")]
      GE[("generations/<br/>cache generation")]
      OP[("opened/<br/>read-only trees")]
    end
  end
  CP["Control plane"]
  A -->|"local_path"| F
  PROC -->|"xratud.cache.v1 metrics<br/>in the heartbeat"| CP

The run route's integrity gate uses the cache manager and the artifact file cache; closure materialization uses the content store. The cache manager lives in process memory and starts empty with each xratud process. The artifact file cache and the content store stay on the node across xratud restarts, and everything in them is verified again before it is reused, so a restart keeps what the node already fetched and leaves outcomes unchanged. See Durable identity on /var/lib/xratu for the node state that lives on the volume.

The cache manager

The cache manager keeps three namespaces of metadata records in memory, each bounded:

Namespace Key Record Capacity
artifact The artifact digest Reference, local path, whether trust was required, when verified artifact_cache_max_entries, default 10,000
env <manifest_id>:<manifest_version> The resolver fingerprint, when cached env_cache_max_entries, default 2,000
model <project>:<binding>:<model> The model traffic target, when cached 128 × max_worker_slots, 4,096 at the default of 32

artifact_cache_max_entries, env_cache_max_entries and max_worker_slots are set in the node's bootstrap profile. See Sizing and capacity planning.

Each namespace evicts its least recently used record when a new record would take it past capacity. A lookup that finds a record makes it the most recent. Keys are matched exactly, and a lookup with an empty key counts as a miss.

The integrity gate writes records after every artifact of a run passes, and reads the artifact namespace at the start of the next run. A record whose local file is gone is invalidated and counted as a miss. See Artifact integrity gate.

The artifact file cache

The run route stores each verified artifact at a path derived from its digest:

<node-local>/xratud_artifact_cache/sha256/<first 2 hex>/<remaining 62 hex>/artifact.bin

The file is written to a temporary name and renamed into place. Before a stored file is reused it is hashed again; a file whose hash differs from its digest is deleted and the run fails with ARTIFACT_INTEGRITY_FAILED.

The file cache and the cache manager are checked separately. After an xratud restart the cache manager is empty while files from the previous process may remain, so the integrity gate reports a miss for an artifact the node then serves from its file without contacting your registry.

The closure content store

Closure artifacts are kept in a content store keyed by content digest:

<node-local>/xratud_runtime_closure_content_<dataplane_uuid>/
  entries/        one metadata record per content digest
  blobs/          the fetched blobs, by blob digest
  generations/    the cache generation recorded for each content digest
  opened/         the opened, read-only tree for each content digest
  .mutation.lock  held exclusively while the store is changed

The path is deterministic for the node, so a restarted xratud finds the store it left and reuses every entry that passes its checks. A node that already holds a closure's artifacts can be preferred when that closure is placed; the closure that runs is the same on any node.

  1. Quota. The quota counts the bytes of resident blobs and comes from content_store_quota_bytes in the closure assignment. A blob already resident is charged once, however many entries share it.
  2. References. Materializing a closure takes one reference on each of its artifacts, and releasing the closure gives them back.
  3. Generations. Each entry's cache_generation only increases. A corrupt or inconsistent entry is evicted and rebuilt under the next generation.
  4. Garbage collection. Entries with no references are removed with their opened trees, and so are blobs that no remaining entry uses and entries whose metadata is malformed.
  5. Writes. One writer changes the store at a time, under its mutation lock, and each file is written to a temporary name and renamed into place.

The store's figures at each materialization appear in its evidence as content_store_accounting. For the evidence fields and the failure codes, see Closure artifact sets and materialization.

Cache metrics

The cache manager's figures are reported as xratud.cache.v1 in every heartbeat, under payload.metadata.cache, and in the cycle summary under cache:

{
  "contract_version": "xratud.cache.v1",
  "namespaces": {
    "artifact": {"size": 412, "capacity": 10000, "hits": 3810, "misses": 422, "puts": 430, "evictions": 0, "invalidations": 18},
    "env":      {"size": 57,  "capacity": 2000,  "hits": 1204, "misses": 61,  "puts": 64,  "evictions": 0, "invalidations": 0},
    "model":    {"size": 9,   "capacity": 4096,  "hits": 0,    "misses": 0,   "puts": 212, "evictions": 0, "invalidations": 0}
  },
  "size_total": 478,
  "hit_count": 5014,
  "miss_count": 483,
  "put_count": 706,
  "eviction_count": 0,
  "invalidation_count": 18,
  "hit_ratio": 0.912
}

Counters start at zero with each xratud process. Read them as follows:

Symptom Cause Action
evictions rising in artifact or env The node serves more distinct artifacts or environments than the namespace holds Raise artifact_cache_max_entries or env_cache_max_entries
invalidations rising in artifact Files in the artifact file cache are disappearing between runs Check what removes files from the node's local storage
hit_ratio low just after a restart The cache manager starts empty with each process None; it rises as runs repeat