Documentation
¶
Index ¶
- Variables
- func ComputeProjectFingerprint(projectPath string) (int64, error)
- func LoadRepoMapFromDisk(projectPath string, fingerprint int64) (string, error)
- func SaveRepoMapToDisk(projectPath string, fingerprint int64, repoMap string) error
- type Cache
- type Clock
- type Config
- type KeyBuilder
- type Metrics
- type RealClock
- type RepoMapCacheEntry
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("cache: not found")
ErrNotFound is returned when a key is not in the cache (or expired).
var ErrRepoMapCacheMiss = errors.New("repomap cache: miss")
Functions ¶
func ComputeProjectFingerprint ¶
ComputeProjectFingerprint computes a best-effort fingerprint based on max modTime.
It walks the project directory and finds the latest modification time across files. Certain directories are excluded to keep it fast and stable.
func LoadRepoMapFromDisk ¶
LoadRepoMapFromDisk loads a cached repo map if fingerprint matches.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a thread-safe TTL + LRU cache.
- If disabled (Config.Enabled=false or Capacity<=0), all operations are no-op and Get returns ErrNotFound. - TTL is optional per entry; 0 means "no expiration" for that entry. - DefaultTTL is applied when Set is called with ttl=0.
This cache is in-memory only (no persistence).
func New ¶
New creates a new cache.
If cfg.Capacity is 0 or negative, the cache behaves as disabled.
func (*Cache) Get ¶
Get returns the cached value for key. It returns ErrNotFound if missing or expired.
func (*Cache) Len ¶
Len returns the number of non-expired entries. It may lazily remove expired entries.
type Clock ¶
Clock abstracts time for testability.
NOTE: Use RealClock in production. Tests can provide a fake clock.
type Config ¶
type Config struct {
Enabled bool
Capacity int // max number of entries; <=0 means 0 (disabled behavior)
DefaultTTL time.Duration // 0 means no expiration by default
}
Config defines cache behavior.
type KeyBuilder ¶
type KeyBuilder struct {
// contains filtered or unexported fields
}
KeyBuilder helps create stable cache keys.
This is intentionally minimal and does not assume any specific caching target. Callers can include provider/model/projectPath/etc. and a content hash.
Example:
kb := cache.NewKeyBuilder("prompt")
key := kb.Add("provider", "openai").Add("model", "gpt-4o").AddHash("system_prompt", prompt).String()
Output format is deterministic.
func NewKeyBuilder ¶
func NewKeyBuilder(prefix string) *KeyBuilder
func (*KeyBuilder) Add ¶
func (k *KeyBuilder) Add(name, value string) *KeyBuilder
func (*KeyBuilder) AddHash ¶
func (k *KeyBuilder) AddHash(name string, content string) *KeyBuilder
func (*KeyBuilder) String ¶
func (k *KeyBuilder) String() string
type RepoMapCacheEntry ¶
type RepoMapCacheEntry struct {
ProjectPath string `json:"project_path"`
Fingerprint int64 `json:"fingerprint"` // UnixNano
RepoMap string `json:"repo_map"`
}
RepoMapCacheEntry is a persisted repo map cache.
Key is derived from project path (hashed for filename safety). Fingerprint is a best-effort project change detector (max modTime across files).
NOTE: This is intentionally conservative: if fingerprint mismatches, cache is ignored. It is not cryptographically strong; it is intended for speed, not security.