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 and call sites keyed by absolute file path and includeBody mode: a body-mode mismatch is always a miss, so both parse modes coexist independently in the same cache.
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, size int64, includeBody bool) (*parser.ParseResult, []parser.CallSite)
Get returns a cached parse result and its call sites for path, scoped to the given includeBody mode. Returns (nil, nil) if not cached, stale (modTime/size mismatch), or cached under the other includeBody mode.
func (*ParseCache) Put ¶
func (c *ParseCache) Put(path string, modTime, size int64, includeBody bool, result *parser.ParseResult, calls []parser.CallSite)
Put stores a parse result and its call sites for path, scoped to the given includeBody mode. Evicts the least-recently-used entry if at capacity.
func (*ParseCache) Stats ¶
func (c *ParseCache) Stats() Stats
Stats returns current cache statistics.