Documentation
¶
Overview ¶
Package cache provides persistent query caching for TokMan. Caches filtered command outputs for instant retrieval on repeated commands.
Index ¶
- func GenerateKey(command string, args []string, workingDir string, fileHashes map[string]string) string
- func GetChangedFiles(workingDir string, oldCommit, newCommit string) ([]string, error)
- func IsGitRepo(workingDir string) bool
- type Cache
- type CacheEntry
- type CacheStats
- type FingerprintCache
- type GitWatcher
- type LRUCache
- type QueryCache
- func (c *QueryCache) Cleanup(maxAge time.Duration) error
- func (c *QueryCache) Close() error
- func (c *QueryCache) Get(key string) (*CacheEntry, bool)
- func (c *QueryCache) GetRuntimeStats() (hits, misses int64)
- func (c *QueryCache) GetTopQueries(limit int) ([]*CacheEntry, error)
- func (c *QueryCache) Invalidate(predicate func(*CacheEntry) bool) error
- func (c *QueryCache) InvalidateByCommand(command string) error
- func (c *QueryCache) InvalidateByPrefix(prefix string) error
- func (c *QueryCache) Set(key string, command string, args []string, workingDir string, ...) error
- func (c *QueryCache) Stats() (*CacheStats, error)
- type RepoState
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
GetChangedFiles returns files changed between two commits
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) 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
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
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