Skip to content

Pricing JSON is re-fetched from the network on every run — add a TTL disk cache #1412

Closed

Description

@pzhang819

What happened

Every non--O run blocks for several seconds re-downloading model pricing. Measured on my machine (v20.0.14):

command run 1 run 2 run 3
ccusage daily -O (embedded) 0.34s 0.30s 0.29s
ccusage daily (online) 10.38s 8.00s 3.32s

The 10.4s run sits right at the 10s fetch timeout. Each run pulls the LiteLLM pricing JSON (~1.5 MB, ~1.5s) and, on the fallback path, models.dev (~2.8 MB, ~1.8s).

Cause

PricingMap::load_with_overrides → fetch_pricing_json / fetch_models_dev_json (rust/crates/ccusage/src/pricing.rs) only memoize in-process (OnceLock); nothing is persisted across invocations, so the network fetch repeats on every run.

Suggested fix

Cache the fetched JSON under $XDG_CACHE_HOME/ccusage (fallback ~/.cache/ccusage) with a TTL (e.g. 24h): a fresh cache hit skips the network, and on a network error we can serve the stale copy. This would cover both the LiteLLM and models.dev URLs, with no new dependencies (std fs/time plus the existing home module).

Note: this is distinct from #1245 (which is about caching usage logs) — this is specifically the pricing fetch.

I'd like to implement this myself.

Version: 20.0.14 · macOS

Activity

  1. github-actions commented on Jul 9, 2026

    @github-actions
    Contributor

    This issue was auto-closed. Issues from new contributors are auto-closed by default.

    Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.

    Keep the issue short, concrete, and written in your own voice.

    If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

    See CONTRIBUTING.md.

  2. ryoppippi commented on Aug 31, 2026

    @ryoppippi
    Member

    Historical audit: this discussion was auto-closed by the legacy contributor gate. That closure did not assess technical importance.

    Audit result: maintainable candidate. The request fits the current ccusage scope and can be evaluated with repository-owned code or fixtures, without vendor credentials or platform-specific release infrastructure. It remains closed for now; reopen only after confirming current relevance and expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage:maintainableFits the repository's maintainable scope and needs review.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions