cache

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtocolCacheName is the filename for the cached /api/mcp/schemas response.
	ProtocolCacheName = "schemas.json"

	// ProtocolCacheTTL is the TTL for protocol schema cache entries.
	ProtocolCacheTTL = 1 * time.Hour
)

Variables

This section is empty.

Functions

func CacheDir

func CacheDir() string

CacheDir returns the directory where kh stores cache files. Defaults to ~/.cache/kh; respects $XDG_CACHE_HOME if set.

func IsStale

func IsStale(entry *CacheEntry, ttl time.Duration) bool

IsStale reports whether the cache entry is older than the given TTL.

func WriteCache

func WriteCache(name string, data json.RawMessage) error

WriteCache serializes data into a CacheEntry with the current UTC time and writes it to the cache directory. The cache directory is created if needed.

func WriteRaw

func WriteRaw(name string, b []byte) error

WriteRaw writes pre-serialized bytes directly to the named cache file. This is useful for tests that need to inject a cache entry with a specific FetchedAt timestamp.

Types

type CacheEntry

type CacheEntry struct {
	FetchedAt time.Time       `json:"fetchedAt"`
	Data      json.RawMessage `json:"data"`
}

CacheEntry wraps cached data with a fetch timestamp.

func ReadCache

func ReadCache(name string) (*CacheEntry, error)

ReadCache reads and unmarshals the named cache file from the cache directory. Returns an error if the file does not exist or cannot be parsed.

Jump to

Keyboard shortcuts

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