Skip to main content

Module cache

Module cache 

Source
Expand description

CACHE: root, session, ids, cursor, URL index, global jobs, page snapshots.

  <root>/index.json                url → {dir, t}          (shared, flock)
  <root>/jobs.json                 [{session, cmd, t}]     j<N> = N-th row, global monotonic (flock)
  <root>/account.json              last `fats account` read: {t, rows: [Account]} (parsed numbers, no answers)
  <root>/swept                     its mtime = the last sweep of every session (`sweep`)
  <root>/pace/<host>               the home-IP brake: the last plain start to that host (`provider::pace`)
  <root>/telemetry/                `ping/` day and week stamps · `days/` day marks · `week/` the weekly tally
                                   (`bump`) · `latest.json` · `sent.jsonl` (`telemetry::at`); not in `usage`
  <root>/<session>/state.json      {u: [{url, dir, alias?, job, serp?}], cursor}
  <root>/<session>/u<N>/           raw.html · meta.json · doc.json (rebuilt from raw.html when stale)
                                   · error.txt (0600): the providers' error answers, masked, never printed
  <root>/<session>/u<N>/assets/    m<K>.<ext> + m<K>.json: picture K of the page, fetched on demand (`Asset`)
  <root>/<session>/j<N>/           meta.json of web search j<N> (hits inside) · error.txt; its results are `serp`
                                   entries with no dir until a command fetches them into the same id
  <root>/<session>/run/u<N>.*      a fetch that outlives its call (`Detached`): .json the run, .lock held by
                                   its process, .log that process's stdout + stderr
  <root>/<session>/run/setup-<p>.* the key form for provider p (`setup::run_file`): .json token, port, deadline;
                                   .log its output

Structs§

Asset
Picture K of a page, fetched on demand (cli::asset): <page>/assets/m<K>.<ext> (ext from its content type), then this record as m<K>.json (written last: no record = not stored). w, h = the size read from the bytes (0 = unread).
Cache
st is a snapshot; every change goes through alloc / save, which re-read state.json under the session lock, so parallel agents in one session never overwrite each other’s ids.
Cursor
Detached
A fetch that outlives its call (past wait:), run/u<N>.json: written by the call that reserved u<N>, then by the process that runs it (fats --continue j<J>.u<N>): its pid once it holds u<N>.lock, status as tiers start and land, done at the end. The lock is held for that process’s life: no done + a free lock = it died. Any other writer writes under that lock, read again there (run_tell).
Done
How a detached fetch ended: what the call that waits for it adds to the stored page’s outline.
Entry
HopRow
One provider call in a fetch’s or search’s hops, as meta.json keeps it: fetch::Hop::row writes it, every view reads its fields. provider is the stored name (brightdata, oxylabs-js); only the fields a view surfaces are kept: provider, code, cost, ms, why (tried/health/fail_detail), and the request budget limit/remaining (limits, kept as the two numbers Oxylabs sends).
Job
Meta
Snap
What Cache::ingest stores.
State
Week
The weekly tally the usage summary is built from (stats::weekly): counts, codes and fixed names only, one file a week (<cache>/telemetry/week/2026-W43.json, this week’s and last week’s kept). Sessions are swept within the hour, so it counts as things happen: a stored fetch or search (tally), a command (stats::tally_run), a panic (stats::crash). n = each counter by its path in the summary (tier\toxyjs\tok), samples = the last week_samples of each tok\tpage (a stored page’s clean tokens), tok\tread (a read’s answer), ms\tplain, ms\tpaid (a page call that served).

Enums§

NoDoc
Why a snapshot has no doc.

Constants§

ERROR_FILE
A failed run’s provider answers (fetch::error_text): stats points at the file, nothing prints it.
MINE
fats made this root (private_root writes it): the sweep deletes only under a root holding it.
SPEND_FILE
THE spend ledger, in the key dir (never swept, so stats still sums what was spent once the pages are gone): one JSON line [unix s, [cost, unverified], "<dir>"] per stored fetch or search record that cost or may have, and per dead run’s calls in flight once its run/ is swept; dir = the record’s path (<root>/default/u3). No URL, no query. A row it cannot write is never a failed fetch: stats probes the file and says why.
WEEK_S

Functions§

assets
The pictures stored under page dir dir (Asset).
build
Body → Doc by its kind (clean::kind_of, kept in meta.json): a PDF, a server’s Markdown, a text document, else a page; og = a JS shell served as its own og card (fetch::og_card), made again from the same body.
bump
Add to this week’s tally (<root>/telemetry/week/), at level full only (a count made under an opt-out would go once it is lifted), under its lock as lock takes it (edit_when); a week’s first write drops every older file but last week’s. A count fats cannot write is lost, never a failed command.
code_of
A code as counted: one errors.json names (js_shell; a * row’s prefix + digits: http_404), else other.
edit
Read-modify-write a shared root file under an exclusive lock.
guarded
A converter panic is an error, never a crash.
jload
jsave
Atomic write: tmp + rename.
now
private_root
The cache root is its owner’s only (0700 on unix): jobs.json keeps every command (queries too), account.json balances. A missing root is created so, with MINE in it, and so is the default root (fats’s own name in the OS cache dir, made by builds before the sweep); one FATS_CACHE names is left as it is (fats shows its mode, config whether it is swept). An error here is reported by the first write (cache_write).
raw_name
The stored body’s file name for a kind: raw.html (also an og card’s), raw.pdf, raw.zip, raw.txt, raw.json, raw.xml.
run_at
The detached run in file json (Cache::run_file) and whether it lives, THE liveness rule (a pending id, status, a batch pool’s floor): its lock is held. The launcher takes it before the run file exists and hands it to the run’s process (Cache::run_claim), so a run not scheduled yet lives too (a 2 s pid-0 window read ! abandoned under load). The lock is probed BEFORE the file is read: a process that wrote done and let go reads as ended with it. A queued run lives while its lane’s process does (the lock of the run it is queued behind, by).
sweep
THE sweep, run after the answer is out (main, mcp): expired dirs of this session every run, of every session at most once per sweep_every_s (the swept file’s mtime), only under a root fats made (MINE), only ours dirs of a session dir (a real dir holding a state.json; a symlink is never followed). A session dir and its state.json stay (ids never restart, so u1 never names another page); the full sweep also forgets what the hour is over for: an index row with its page, a job’s command once cache_ttl_s old, and a history row’s URL (a search’s results too) once its page is gone and its job forgotten: its id reads ! expired.
tally
Count a stored fetch or search record (cache::ingest, cache::serp_put): its calls per tier (a call cut after the other provider won is neither ok nor failed) and paid provider, each failed call’s code and the record’s own when no call ended with it (no_key), the serving page call’s ms, the page’s clean tokens (tok), a PDF. No URL, no query: every name comes from our tables.
url_key
usage
Bytes under the root, the pictures among them (assets/), every live snapshot’s meta.json path (expired: the sweep’s rule, so a dead copy counts in no health row), all sessions (status: size, pages, provider health). Telemetry’s telemetry/ (its stamps, day marks and the weekly tally Week) is no cached page: a command’s own count never changes the next’s status.
week_of
2026-W43: the ISO week of unix time t.