Skip to main content

Module cache

Module cache 

Source
Expand description

Per-vendor on-disk cache with atomic writes, TTL checks, and inter-process locking.

Mirrors claudebar’s cache layout but per-vendor: ~/.cache/ai-usagebar/<vendor>/usage.json payload ~/.cache/ai-usagebar/<vendor>/.stale marker (cache is stale) ~/.cache/ai-usagebar/<vendor>/.last_error HTTP code\nmessage ~/.cache/ai-usagebar/<vendor>/.fetch.lock flock target

Multi-monitor safety: callers should acquire_lock() before the refresh+ fetch window, mirroring claudebar:402-407’s exec 9>"$_lockfile" / flock.

Structs§

Cache
Per-vendor cache directory and helper API.
LockGuard
Releases the flock on drop. Holding this across an .await is fine as long as you don’t move it across tasks (we always use it in tokio::main on a single thread).

Constants§

DEFAULT_TTL
Default TTL — claudebar’s CACHE_TTL=60.
MAX_STALE
Maximum staleness before we refuse to serve cached data even on failure. Mirrors claudebar’s WEEKLY_WINDOW (7 days).

Functions§

acquire_lock
Acquire an exclusive flock on path, blocking up to timeout. Returned guard releases the lock on drop.
atomic_write
Atomic write helper used by write_last_error. Public for vendors that need to write small sidecar files (credentials, etc.).
home_dir
The user’s home directory, resolved cross-platform via directories ($HOME on Unix/macOS, %USERPROFILE% / the Known Folder on Windows).