cache

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
const (
	DefaultParseCacheSize = 5000
	DefaultLLMCacheSize   = 500
	DefaultLLMTTL         = time.Hour
)

Default cache sizes.

Variables

This section is empty.

Functions

func Key

func Key(parts ...string) string

Key generates a deterministic cache key from parts using FNV-128a.

func PromptHash

func PromptHash(systemPrompt, userPrompt string) uint64

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

func NewLLMCache(maxSize int, ttl time.Duration) *LLMCache

NewLLMCache creates an LLM response cache with the given size and TTL.

func (*LLMCache) Get

func (c *LLMCache) Get(key uint64) (string, bool)

Get returns a cached LLM response if present and not expired.

func (*LLMCache) Put

func (c *LLMCache) Put(key uint64, response string)

Put stores an LLM response. Evicts the least-frequently-used entry if at capacity.

func (*LLMCache) Stats

func (c *LLMCache) Stats() Stats

Stats returns current cache statistics.

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

func (c *LRU[K, V]) Get(key K) (V, bool)

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.

func (*LRU[K, V]) Len added in v1.22.0

func (c *LRU[K, V]) Len() int

Len returns the number of entries currently in the cache.

func (*LRU[K, V]) Set added in v1.22.0

func (c *LRU[K, V]) Set(key K, value V)

Set inserts or updates key with value, evicting the LRU entry if at capacity.

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.

type Stats

type Stats struct {
	Hits    int64 `json:"hits"`
	Misses  int64 `json:"misses"`
	Entries int   `json:"entries"`
}

Stats holds cache hit/miss counters.

Jump to

Keyboard shortcuts

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