Skip to main content

Module account_cache

Module account_cache 

Source
Expand description

Persistent forge state: the per-account usage cache.

It lives in the machine-local redb store (crate::store::state). load and store are thin wrappers over that tenant; ForgeState / CachedAccountUsage are the in-memory shapes.

The usage cache solves the cold-boot problem: Anthropic’s /api/oauth/usage endpoint rate-limits aggressively on per-IP burst probes, so the first launch can wait 30 s+ before the warm probe gets through - during which the launchpad picker has no usage to show and the walk sees every account as unknown. The cache seeds the in-memory AccountStateMap with the last known values until the 60 s poller refreshes them.

Failures are non-fatal: a closed store degrades to β€œno cache; spawn paths see empty bars until the poller succeeds.”

Re-exportsΒ§

use forge_primitives::usage::UsageSnapshot; πŸ”’
use serde::Deserialize; πŸ”’
use serde::Deserialize; πŸ”’
use serde::Serialize; πŸ”’
use serde::Serialize; πŸ”’

StructsΒ§

CachedAccountUsage
Per-account cache entry. The value type of the redb account_usage table; reachable only in-crate since account_cache is a private mod.
ForgeState πŸ”’
In-memory forge state read from the redb store.

FunctionsΒ§

load πŸ”’
Read the persisted forge state from the store. Each read degrades to its empty default with a warn rather than failing the boot.
store πŸ”’
Persist the in-memory account-usage snapshots, replacing the prior set. Backs the 60 s poller. Non-fatal + logged on failure.