Documentation
¶
Overview ¶
Package cache provides in-memory caches for parsed ASTs and LLM responses.
Both caches use LRU eviction and are safe for concurrent access.
Index ¶
Constants ¶
const ( DefaultParseCacheSize = 5000 DefaultLLMCacheSize = 500 DefaultLLMTTL = time.Hour )
Default cache sizes.
Variables ¶
This section is empty.
Functions ¶
func PromptHash ¶
PromptHash computes the FNV-1a hash of system + user prompt pair.
Types ¶
type LLMCache ¶
type LLMCache struct {
// contains filtered or unexported fields
}
LLMCache caches LLM completion responses keyed by FNV-1a hash of prompts.
func NewLLMCache ¶
NewLLMCache creates an LLM response cache with the given size and TTL.
type LRU ¶ added in v1.22.0
type LRU[K comparable, V any] struct { // contains filtered or unexported fields }
LRU is a generic O(1) LRU cache backed by a doubly-linked list. It is NOT safe for concurrent use; callers must hold their own mutex. Zero value is invalid; use NewLRU.
func NewLRU ¶ added in v1.22.0
func NewLRU[K comparable, V any](maxSize int) *LRU[K, V]
NewLRU creates an LRU cache with the given maximum capacity. maxSize must be > 0.
func (*LRU[K, V]) Delete ¶ added in v1.22.0
func (c *LRU[K, V]) Delete(key K)
Delete removes key from the cache. No-op if absent.
func (*LRU[K, V]) Get ¶ added in v1.22.0
Get returns the value for key and true, or the zero value and false if absent. Accessing a key moves it to the most-recently-used position.
type ParseCache ¶
type ParseCache struct {
// contains filtered or unexported fields
}
ParseCache caches tree-sitter parse results keyed by absolute file path.
func NewParseCache ¶
func NewParseCache(maxSize int) *ParseCache
NewParseCache creates a parse cache with the given maximum entry count.
func (*ParseCache) Get ¶
func (c *ParseCache) Get(path string, modTime int64, size int64) *parser.ParseResult
Get returns a cached parse result if the file hasn't changed. Returns nil if not cached or stale (modTime/size mismatch).
func (*ParseCache) Put ¶
func (c *ParseCache) Put(path string, modTime int64, size int64, result *parser.ParseResult)
Put stores a parse result. Evicts the least-recently-used entry if at capacity.
func (*ParseCache) Stats ¶
func (c *ParseCache) Stats() Stats
Stats returns current cache statistics.