cache

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheBucket      = "cache"
	CacheStatsBucket = "cache_stats"
	DefaultTTL       = 2 * time.Hour
	CleanupInterval  = 10 * time.Minute
)

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey(toolName string, args map[string]interface{}, timestamp time.Time) string

GenerateKey generates a cache key from tool name, arguments, and timestamp

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles cached tool responses

func NewManager

func NewManager(db *bbolt.DB, logger *zap.Logger) (*Manager, error)

NewManager creates a new cache manager

func (*Manager) Close

func (m *Manager) Close()

Close stops the cache manager

func (*Manager) Get

func (m *Manager) Get(key string) (*Record, error)

Get retrieves a cached tool response

func (*Manager) GetRecords

func (m *Manager) GetRecords(key string, offset, limit int) (*ReadCacheResponse, error)

GetRecords retrieves paginated records from a cached response

func (*Manager) GetStats

func (m *Manager) GetStats() *Stats

GetStats returns current cache statistics

func (*Manager) Store

func (m *Manager) Store(key, toolName string, args map[string]interface{}, content, recordPath string, totalRecords int) error

Store saves a tool response to cache

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) IsExpired

func (c *Record) IsExpired() bool

IsExpired checks if the cache record has expired

func (*Record) MarshalBinary

func (c *Record) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler for Record

func (*Record) UnmarshalBinary

func (c *Record) UnmarshalBinary(data []byte) error

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

func (s *Stats) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler for Stats

func (*Stats) UnmarshalBinary

func (s *Stats) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler for Stats

Jump to

Keyboard shortcuts

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