Documentation
¶
Index ¶
- Constants
- func GenerateKey(toolName string, args map[string]interface{}, timestamp time.Time) string
- type Manager
- func (m *Manager) Close()
- func (m *Manager) Get(key string) (*Record, error)
- func (m *Manager) GetRecords(key string, offset, limit int) (*ReadCacheResponse, error)
- func (m *Manager) GetStats() *Stats
- func (m *Manager) Invalidate(key string) error
- func (m *Manager) InvalidatePrefix(prefix string) (int, error)
- func (m *Manager) Peek(key string) (*Record, bool)
- func (m *Manager) Refresh(key string) error
- func (m *Manager) Store(key, toolName string, args map[string]interface{}, content, recordPath string, ...) error
- type Meta
- type PathSegment
- type ReadCacheResponse
- type Record
- type Stats
Constants ¶
const ( CacheBucket = "cache" CacheStatsBucket = "cache_stats" DefaultTTL = 2 * time.Hour CleanupInterval = 10 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
GenerateKey generates a cache key from tool name, arguments, and timestamp.
The timestamp is mixed in at nanosecond granularity. The truncator calls this with time.Now() once per truncated payload; a single upstream result can carry multiple oversized TextContent blocks, and recursive read_cache truncation can mint several keys in quick succession. At second granularity any of those that landed in the same wall-clock second collided on one key, so a later Store silently overwrote an earlier payload and the earlier banner resolved to the wrong data. Nanosecond granularity makes each call's key unique in practice.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles cached tool responses
func NewManager ¶
NewManager creates a new cache manager
func (*Manager) GetRecords ¶
func (m *Manager) GetRecords(key string, offset, limit int) (*ReadCacheResponse, error)
GetRecords retrieves paginated records from a cached response
func (*Manager) Invalidate ¶ added in v0.35.0
Invalidate removes a single cache entry, forcing the next access to miss. It is a no-op (nil error) if the key is absent. Used by the registry refresh path (FR-007) to drop cached server lists on demand.
func (*Manager) InvalidatePrefix ¶ added in v0.35.0
InvalidatePrefix removes every cache entry whose key starts with prefix and returns how many were deleted. Registry caches are keyed by a stable prefix (e.g. "registry-servers:<id>:") so a single refresh can drop all variants of a registry's cached results regardless of tag/query/limit (FR-007).
func (*Manager) Peek ¶ added in v0.35.0
Peek returns a cached record WITHOUT evicting it or mutating access stats, even when the entry has expired. Unlike Get (which deletes expired entries and is the read path for fresh data), Peek lets the registry layer serve a stale value while still flagging its age — callers derive freshness from time.Since(record.CreatedAt) and record.IsExpired() (FR-007). The boolean is false only when the key is absent.
func (*Manager) Refresh ¶ added in v0.35.0
Refresh forces the next access to re-fetch by invalidating the cached entry. The cache manager has no knowledge of the upstream source, so "refresh" is a lazy operation: it drops the stale value and the caller re-populates it on the next Store. Provided alongside Invalidate to match the data model (FR-007).
type Meta ¶
type Meta struct {
Key string `json:"key"`
TotalRecords int `json:"total_records"`
Limit int `json:"limit"`
Offset int `json:"offset"`
TotalSize int `json:"total_size"`
RecordPath string `json:"record_path,omitempty"`
}
Meta represents metadata about the cached response
type PathSegment ¶
type PathSegment struct {
Type string // "object", "array", or "parsed"
Key string // for object access
Index int // for array access
}
PathSegment represents a segment of a JSON path
type ReadCacheResponse ¶
type ReadCacheResponse struct {
Records []interface{} `json:"records"`
Meta Meta `json:"meta"`
}
ReadCacheResponse represents the response structure for read_cache tool
type Record ¶
type Record struct {
Key string `json:"key"`
ToolName string `json:"tool_name"`
Args map[string]interface{} `json:"args"`
Timestamp time.Time `json:"timestamp"`
FullContent string `json:"full_content"`
RecordPath string `json:"record_path,omitempty"` // JSON path to records array
TotalRecords int `json:"total_records,omitempty"` // Total number of records
TotalSize int `json:"total_size"` // Full response size in characters
ExpiresAt time.Time `json:"expires_at"`
AccessCount int `json:"access_count"`
LastAccessed time.Time `json:"last_accessed"`
CreatedAt time.Time `json:"created_at"`
}
Record represents a cached tool response
func (*Record) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler for Record
func (*Record) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler for Record
type Stats ¶
type Stats struct {
TotalEntries int `json:"total_entries"`
TotalSizeBytes int `json:"total_size_bytes"`
HitCount int `json:"hit_count"`
MissCount int `json:"miss_count"`
EvictedCount int `json:"evicted_count"`
CleanupCount int `json:"cleanup_count"`
}
Stats represents cache statistics
func (*Stats) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler for Stats
func (*Stats) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler for Stats