cache

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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