TTL
Every frame carries a TTL (time-to-live) that sets how long the store keeps
it. The default is forever. A frame's TTL is fixed when it is appended and
never changes afterward.
Kinds
| TTL | Query form | Meaning |
|---|---|---|
| Forever | forever (default) | Kept indefinitely. |
| Ephemeral | ephemeral | Never written to the store. Only readers following live at the moment of the append see it. |
| Time | time:<ms> | Kept for <ms> milliseconds after the frame's creation, then removed. |
| Last | last:<n> | Retains only the newest n frames on the frame's topic (n >= 1); older frames on that topic are removed. |
Setting a TTL
From Nushell, pass --ttl to .append:
| . greeting # forever (default)
| . clock --ttl ephemeral
| . logs --ttl time: # 60s
$state | . game.score --ttl : # keep only the latest
Over HTTP, set the ttl query parameter on the append endpoint
(?ttl=last:1). The wire forms are exactly the query strings in the table
above.
How each kind behaves
-
foreveris the default, and the right choice for anything another part of the system reads back later. -
ephemeralframes are broadcast but never persisted, so they never appear in.cathistory or on replay. Use them for liveness signals where a missed frame does not matter. -
time:<ms>frames expire relative to their own creation timestamp. A read never returns an expired frame, so expiry is immediate as far as any reader is concerned. A background sweeper then removes them from disk. It wakes at most once per sweep interval,xs serve --ttl-sweep, default one second, and removes a bounded batch each time, so clearing a large backlog takes several passes. No read has to touch a frame for it to be removed. -
last:<n>trims the topic to itsnmost recent frames. The trim runs on the append that carries it, in the same commit, so that append never leaves the topic overn. Reads are unaffected -- they return whatever is stored. This is retention by topic, not by frame, so a trim takes whatever is oldest, whatever ttl those frames carry.Frames appended without a
last:ndo not trim, so a topic grows freely between them. The nextlast:nappend counts those frames too and takes the topic back ton. Appending onelast:nframe is therefore a way to collapse a topic on demand: let it accumulate, trim it when you want to, let it grow again.A topic that is already well over its limit -- because
nwas lowered, or because frames were restored into it -- is brought down by the background worker instead, a batch at a time, since one append cannot clear it.
Adding last:n to a topic that already has frames
To keep a topic at
n, the store counts how many frames it holds. A topic counts from its firstlast:nframe, so putting alast:non a topic that has been accumulating frames without one makes that append walk the topic to establish the count.It happens once for the life of the store, and writes to every topic wait while it runs. On a topic of a few million frames that is under a second. Capping a topic while it is small avoids it entirely.
Do not put a pruning TTL on module topics
Processors resolve their modules as of their own
.createframe: a service, actor, or action sees thexs.module.<name>versions whose frame id is at or below its create id (see Module Topics).
last:<n>andtime:delete older frames on a topic. If you prunexs.module.<name>, you can delete the module version that an already-registered processor's create id resolves against. The next time that processor spawns (a restart, a replay, or a hot-replace), the only surviving module frame has a higher id than its create frame, so it is skipped, and the matching older one is gone. The script'suse <name>then fails withModuleNotFound.It looks intermittent because whether it fires depends on the newest module frame's id versus each processor's create id, but it is not a race.
The rule: retain a module version for at least as long as anything relies on it, that is, as long as a registered processor's create id resolves against it. The simplest way to guarantee that is to leave module topics on the default
forever. If you prune withlast:<n>,nmust cover every version still resolved by a live processor. To update a module, append the new version and re-register the dependent processors so their new create ids resolve to it.