cache

package
v1.0.23 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RegistryTTL     = 24 * time.Hour
	ToolsTTL        = 7 * 24 * time.Hour
	DetailTTL       = 7 * 24 * time.Hour
	RevalidateAfter = 1 * time.Hour
)

Variables

This section is empty.

Functions

func ChangedServerKeysByUpdatedAt

func ChangedServerKeysByUpdatedAt(cached, live []market.ServerDescriptor) map[string]bool

ChangedServerKeysByUpdatedAt returns the set of live server keys that should be refreshed because they are new or their existing registry updatedAt value changed. This intentionally uses only existing market registry metadata.

func ExtractActionVersions

func ExtractActionVersions(detailTools []market.DetailTool) map[string]string

ExtractActionVersions builds a tool-name → actionVersion map from detail tools.

func HasActionVersionChanged

func HasActionVersionChanged(cached map[string]string, detailTools []market.DetailTool) bool

HasActionVersionChanged compares cached actionVersion strings against the versions reported by a fresh Detail API response. It returns true when at least one tool's version has changed, signalling that the tools cache should be refreshed even if the TTL has not expired.

func IsNotExist

func IsNotExist(err error) bool

func ShouldRevalidate

func ShouldRevalidate(now, savedAt time.Time) bool

ShouldRevalidate reports whether a still-valid snapshot is old enough to merit a live revalidation attempt before trusting it as the current truth.

Types

type DetailSnapshot

type DetailSnapshot struct {
	SavedAt time.Time       `json:"saved_at"`
	MCPID   int             `json:"mcp_id"`
	Payload json.RawMessage `json:"payload"`
}

type Freshness

type Freshness string
const (
	FreshnessFresh Freshness = "fresh"
	FreshnessStale Freshness = "stale"
)

type RegistrySnapshot

type RegistrySnapshot struct {
	SavedAt time.Time                 `json:"saved_at"`
	Servers []market.ServerDescriptor `json:"servers"`
}

type Store

type Store struct {
	Root string
	Now  func() time.Time
}

func NewStore

func NewStore(root string) *Store

func (*Store) DeleteDetail

func (s *Store) DeleteDetail(partition, serverKey string) error

DeleteDetail removes the cached detail snapshot for a server.

func (*Store) DeleteTools

func (s *Store) DeleteTools(partition, serverKey string) error

DeleteTools removes the cached tools snapshot for a server, forcing a re-fetch on the next DiscoverServerRuntime call.

func (*Store) ListToolsCacheEntries

func (s *Store) ListToolsCacheEntries(partition string) ([]ToolsCacheEntrySummary, error)

ListToolsCacheEntries walks the cache directory and returns a summary for each server whose tools snapshot is cached.

func (*Store) LoadDetail

func (s *Store) LoadDetail(partition, serverKey string) (DetailSnapshot, Freshness, error)

func (*Store) LoadRegistry

func (s *Store) LoadRegistry(partition string) (RegistrySnapshot, Freshness, error)

func (*Store) LoadTools

func (s *Store) LoadTools(partition, serverKey string) (ToolsSnapshot, Freshness, error)

func (*Store) SaveDetail

func (s *Store) SaveDetail(partition, serverKey string, snapshot DetailSnapshot) error

func (*Store) SaveRegistry

func (s *Store) SaveRegistry(partition string, snapshot RegistrySnapshot) error

func (*Store) SaveTools

func (s *Store) SaveTools(partition, serverKey string, snapshot ToolsSnapshot) error

type ToolsCacheEntrySummary

type ToolsCacheEntrySummary struct {
	ServerKey    string    `json:"server_key"`
	Freshness    Freshness `json:"freshness"`
	SavedAt      time.Time `json:"saved_at"`
	ToolCount    int       `json:"tool_count"`
	TTLRemaining string    `json:"ttl_remaining"`
}

ToolsCacheEntrySummary summarises one cached tools snapshot.

type ToolsSnapshot

type ToolsSnapshot struct {
	SavedAt         time.Time                  `json:"saved_at"`
	ServerKey       string                     `json:"server_key"`
	ProtocolVersion string                     `json:"protocol_version"`
	Tools           []transport.ToolDescriptor `json:"tools"`
	ActionVersions  map[string]string          `json:"action_versions,omitempty"`
}

Jump to

Keyboard shortcuts

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