The cache spectrum
Each kind of data lives on one rung, chosen on purpose. Climb only when the rung below is too slow for who reads it; never keep the same fact as truth on two rungs.
| Rung | What lives there | Read cost | Changes | Truth? |
|---|---|---|---|---|
| git | code, forge.json, the repository's own files | a git read | a push | yes — the only truth (CLAUDE.md, invariant 4) |
| SQLite | the derived index (issues, pulls, events), config rows and their ledger (config, config_change), sessions | one indexed query | every action | derived from git, except config and sessions |
| process | the current config snapshot of each scope, held by every forge process | a map lookup | refreshed on the config.set bus event, or by a half-second poll for another process's write | a copy of SQLite |
| edge | the signed snapshot file, at a stable URL and (behind Cloudflare) in KV | none of the forge's | published within seconds of a write | a copy of SQLite |
| validator | ETag + If-None-Match: the client keeps the body, the forge answers 304 | a lookup | per request | n/a |
Which data, which rung
- Flags, settings, the forge's and an app's config — small, read
everywhere, written rarely: the config store (
src/core/config.ts). Truth in SQLite, copy in every process, signed copy on the edge. Values are public by contract; secrets go in the secret store, never here. - Pages, lists, issues, pulls — large, personal, changing: SQLite, with
fragmentorconfigvalidators. Not the edge. - Content-addressed assets (
/assets/<hash>.css) —immutable. - Repository contents — git, read through the pooled
cat-filereaders.
One helper per kind
Cache-Control and ETag come from cacheHeaders(kind, etag) and
cached(...) in src/http/respond.ts; a route names the kind and never
writes the header. The table CACHE_CONTROL is the single source and
test/config-store.test.ts checks this page against it.
| Kind | Cache-Control | ETag | Used for |
|---|---|---|---|
immutable | public, max-age=31536000, immutable | optional | content-addressed assets; web/asset.ts keeps its own literal header of the same value |
edge | public, max-age=5, stale-while-revalidate=30 | snapshot id | the published snapshot, the forge's public config |
config | private, no-cache | snapshot id | an app's config for its signed-in reader |
live | no-store | never | anything that must not be kept |
Routes that predate the helper still set their own headers
(web/pages/*, apps/proxy.ts); they move to a kind as they are touched.
The edge rung
Every write produces one snapshot id. Each process that learns of it
publishes <data>/edge/config/<name>.json, an Ed25519-signed
{ payload, sig }, served at /edge/config/<name>.json (forge, or
app-<id> for an app whose repository anyone can read). The public key is
at /edge/config/key.pem. With FORGE_CF_ACCOUNT, FORGE_CF_KV_NAMESPACE
and FORGE_CF_API_TOKEN set, the same bytes are also PUT to that KV
namespace under the same name, so a Worker reads flags without the forge.
A stale edge is visible. Every response carries X-Forge-Config, the id
of the snapshot this forge holds; compare it with the snapshot in the file
you have.
Apps
GET /api/v1/apps/:slug/config (any credential that can read the app, so
the read-only token an app starts with) returns
{ snapshot, version, values, updated_at } with the id as ETag; send it
back as If-None-Match for a 304. PATCH with { "set": { key: value |
null }, "why": "…" } needs an admin token and repository admin. The edge
file of a public app is the same data without the forge.
The MCP tools and the terminal door are not built yet (the change carries a No door: line); an app's client is in docs/features/config.md.
Checking the choice
GET /api/v1/cache (admin) returns this process's hit/miss counts per rung:
process (snapshot already held), sqlite (loaded or refreshed), edge
(published file served), validator (304s). The counters are in memory
and reset with the process.