ccstatusline icon indicating copy to clipboard operation
ccstatusline copied to clipboard

feat(usage): invalidate the usage cache when the account token changes

Open zachthedev opened this issue 5 months ago • 0 comments

Closes #459

The cache was keyed only by CACHE_MAX_AGE, so a logout/login to another account served the prior account's usage until the 180s TTL.

Fingerprints the token (truncated SHA-256; an identifier, not the token) and persists it in the cache. fetchUsageData resolves the token first and gates the file-cache read on a fingerprint match; a mismatch refetches immediately.

  • No token: gate is a no-op (existing no-token path).
  • Pre-fingerprint caches refetch once on upgrade.
  • The OAuth token rotates per account, so this also busts on rotation (one extra refetch); stable account-id keying is out of scope.

Complements #434. Tests: account-switch (mismatch refetches) + same-account (match serves). bun run lint clean; bun test 1554/1554.

zachthedev avatar Jun 16 '26 02:06 zachthedev