Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v0.53.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache provides caching for provider usage data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SourceRevisionMatches added in v0.33.0

func SourceRevisionMatches(cached map[string]string, name, current string) bool

SourceRevisionMatches compares provenance symmetrically. An unrevisioned source matches only an unrevisioned cache entry; this prevents a source key that changes between native and explicit credentials from reusing old data.

func UpdateProvider added in v0.35.0

func UpdateProvider(name string, data *provider.UsageData, sourceRevision string) error

UpdateProvider merges one locally observed provider source without extending the freshness lifetime of the other providers in the cache.

func Write

func Write(result *provider.MultiFetchResult) error

Write saves usage data to the cache.

Types

type Entry

type Entry struct {
	Version int `json:"version,omitempty"`
	// ProviderData maps canonical source key to usage data. The legacy `claude`
	// key remains the default Claude source.
	ProviderData    map[string]*provider.UsageData `json:"provider_data"`
	SourceRevisions map[string]string              `json:"source_revisions,omitempty"`
	FetchedAt       time.Time                      `json:"fetched_at"`
}

Entry represents cached usage data for all providers.

func Read

func Read() (*Entry, error)

Read loads cached usage data from disk.

func (*Entry) Covers

func (e *Entry) Covers(want []string) bool

Covers reports whether the cache contains an entry — error or data — for every name in want. Callers use this in addition to IsValid to avoid serving a stale cache that pre-dates a provider becoming configured: e.g. the user runs `codex login` after a stale cache was written; without this check, status would return empty until the TTL expired.

func (*Entry) CoversCurrent added in v0.33.0

func (e *Entry) CoversCurrent(want []string, revisions map[string]string) bool

func (*Entry) GetProvider

func (e *Entry) GetProvider(name string) (*provider.UsageData, bool)

GetProvider retrieves usage data for a specific provider.

func (*Entry) HasStaleData

func (e *Entry) HasStaleData(want []string) bool

HasStaleData reports whether any requested provider is cached fallback data.

func (*Entry) IsProviderStale added in v0.39.2

func (e *Entry) IsProviderStale(name string) bool

IsProviderStale uses the reading's own timestamp so a local update neither inherits nor refreshes another source's age. Legacy readings without a timestamp fall back to the aggregate age; a missing timestamp stays stale.

func (*Entry) IsStale added in v0.39.2

func (e *Entry) IsStale() bool

IsStale reports when cached-only output must warn about its age.

func (*Entry) IsValid

func (e *Entry) IsValid() bool

IsValid returns true if the cache entry is fresh (within TTL).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL