cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT 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 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