cache

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package cache provides persistent query caching for TokMan. Caches filtered command outputs for instant retrieval on repeated commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey added in v0.28.0

func GenerateKey(command string, args []string, workingDir string, fileHashes map[string]string) string

GenerateKey creates a cache key from command context

func GetChangedFiles added in v0.28.0

func GetChangedFiles(workingDir string, oldCommit, newCommit string) ([]string, error)

GetChangedFiles returns files changed between two commits

func IsGitRepo added in v0.28.0

func IsGitRepo(workingDir string) bool

IsGitRepo checks if a directory is a git repository

Types

type Cache added in v0.28.0

type Cache interface {
	Get(key string) (interface{}, bool)
	Set(key string, value interface{})
	Delete(key string)
	Len() int
}

Cache interface defines a generic cache

type CacheEntry added in v0.28.0

type CacheEntry struct {
	Key              string    `json:"key"`
	Command          string    `json:"command"`
	Args             string    `json:"args"`
	WorkingDir       string    `json:"working_dir"`
	FileHashes       string    `json:"file_hashes"`
	FilteredOutput   string    `json:"filtered_output"`
	OriginalTokens   int       `json:"original_tokens"`
	FilteredTokens   int       `json:"filtered_tokens"`
	CompressionRatio float64   `json:"compression_ratio"`
	CreatedAt        time.Time `json:"created_at"`
	AccessedAt       time.Time `json:"accessed_at"`
	HitCount         int       `json:"hit_count"`
}

CacheEntry represents a cached query result

type CacheStats

type CacheStats struct {
	TotalEntries int64   `json:"total_entries"`
	TotalHits    int64   `json:"total_hits"`
	TotalMisses  int64   `json:"total_misses"`
	HitRate      float64 `json:"hit_rate"`
	TotalSaved   int64   `json:"total_tokens_saved"`
}

CacheStats holds cache statistics

type FingerprintCache

type FingerprintCache struct {
	// contains filtered or unexported fields
}

func GetGlobalCache

func GetGlobalCache() *FingerprintCache

func NewFingerprintCache

func NewFingerprintCache() *FingerprintCache

func (*FingerprintCache) Get

func (c *FingerprintCache) Get(key string) (string, bool)

func (*FingerprintCache) Set

func (c *FingerprintCache) Set(key, value string)

type GitWatcher added in v0.28.0

type GitWatcher struct {
	// contains filtered or unexported fields
}

GitWatcher monitors git state for cache invalidation

func NewGitWatcher added in v0.28.0

func NewGitWatcher(cache *QueryCache) *GitWatcher

NewGitWatcher creates a new git watcher

func (*GitWatcher) GetFileHashes added in v0.28.0

func (w *GitWatcher) GetFileHashes(workingDir string, files []string) (map[string]string, error)

GetFileHashes returns hashes for files in a directory Used to generate cache keys and detect changes

func (*GitWatcher) InvalidateChanged added in v0.28.0

func (w *GitWatcher) InvalidateChanged(workingDir string) error

InvalidateChanged invalidates cache entries for changed files

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRUCache implements a true LRU cache with O(1) operations

func NewLRUCache

func NewLRUCache(capacity int, ttl time.Duration) *LRUCache

func (*LRUCache) Delete

func (c *LRUCache) Delete(key string)

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (interface{}, bool)

func (*LRUCache) Len added in v0.28.0

func (c *LRUCache) Len() int

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value interface{})

type QueryCache added in v0.28.0

type QueryCache struct {
	// contains filtered or unexported fields
}

QueryCache provides persistent caching of filtered outputs

func NewQueryCache added in v0.28.0

func NewQueryCache(dbPath string) (*QueryCache, error)

NewQueryCache creates a new query cache

func (*QueryCache) Cleanup added in v0.28.0

func (c *QueryCache) Cleanup(maxAge time.Duration) error

Cleanup removes old entries

func (*QueryCache) Close added in v0.28.0

func (c *QueryCache) Close() error

Close closes the cache database

func (*QueryCache) Get added in v0.28.0

func (c *QueryCache) Get(key string) (*CacheEntry, bool)

Get retrieves a cached entry

func (*QueryCache) GetRuntimeStats added in v0.28.0

func (c *QueryCache) GetRuntimeStats() (hits, misses int64)

GetStats returns runtime hit/miss stats

func (*QueryCache) GetTopQueries added in v0.28.0

func (c *QueryCache) GetTopQueries(limit int) ([]*CacheEntry, error)

GetTopQueries returns most frequently accessed queries

func (*QueryCache) Invalidate added in v0.28.0

func (c *QueryCache) Invalidate(predicate func(*CacheEntry) bool) error

Invalidate removes entries matching a predicate

func (*QueryCache) InvalidateByCommand added in v0.28.0

func (c *QueryCache) InvalidateByCommand(command string) error

InvalidateByCommand removes all entries for a command

func (*QueryCache) InvalidateByPrefix added in v0.28.0

func (c *QueryCache) InvalidateByPrefix(prefix string) error

InvalidateByPrefix removes entries with working dir prefix

func (*QueryCache) Set added in v0.28.0

func (c *QueryCache) Set(key string, command string, args []string, workingDir string,
	fileHashes map[string]string, filteredOutput string,
	originalTokens, filteredTokens int) error

Set stores a new cache entry

func (*QueryCache) Stats added in v0.28.0

func (c *QueryCache) Stats() (*CacheStats, error)

Stats returns cache statistics

type RepoState added in v0.28.0

type RepoState struct {
	WorkingDir  string
	HeadCommit  string
	DirtyFiles  map[string]string // file -> hash
	LastChecked time.Time
}

RepoState tracks the state of a git repository

Jump to

Keyboard shortcuts

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