Documentation
¶
Overview ¶
Package cache provides caching for provider usage data.
Index ¶
- func SourceRevisionMatches(cached map[string]string, name, current string) bool
- func UpdateProvider(name string, data *provider.UsageData, sourceRevision string) error
- func Write(result *provider.MultiFetchResult) error
- type Entry
- func (e *Entry) Covers(want []string) bool
- func (e *Entry) CoversCurrent(want []string, revisions map[string]string) bool
- func (e *Entry) GetProvider(name string) (*provider.UsageData, bool)
- func (e *Entry) HasStaleData(want []string) bool
- func (e *Entry) IsProviderStale(name string) bool
- func (e *Entry) IsStale() bool
- func (e *Entry) IsValid() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SourceRevisionMatches ¶ added in v0.33.0
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
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 (*Entry) Covers ¶
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 (*Entry) GetProvider ¶
GetProvider retrieves usage data for a specific provider.
func (*Entry) HasStaleData ¶
HasStaleData reports whether any requested provider is cached fallback data.
func (*Entry) IsProviderStale ¶ added in v0.39.2
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.