Documentation
¶
Overview ¶
Package cache provides file-based caching for parsed AST nodes.
This package enables incremental duplicate detection by caching the parsed AST nodes for each file. When a file hasn't changed (same content hash), its cached AST can be reused instead of re-parsing.
Cache Structure:
.cache/art-dupl/ ├── files/ │ ├── <hash1>.gob # Serialized AST nodes for file with hash1 │ ├── <hash2>.gob # Serialized AST nodes for file with hash2 │ └── ... └── metadata.json # Cache metadata (version, timestamps)
Usage:
cache := cache.NewFileCache(".cache/art-dupl")
nodes, hit := cache.Get(fileHash)
if !hit {
nodes = parseFile(path)
cache.Set(fileHash, nodes)
}
Index ¶
- Constants
- func Key(content []byte) string
- type FileCache
- func (fc *FileCache) Clear() error
- func (fc *FileCache) Get(contentHash string) ([]*syntax.Node, bool)
- func (fc *FileCache) Has(contentHash string) bool
- func (fc *FileCache) Prune(maxEntries int) (int, error)
- func (fc *FileCache) Remove(contentHash string) error
- func (fc *FileCache) Set(contentHash string, nodes []*syntax.Node) error
- func (fc *FileCache) Stats() Stats
- type Metadata
- type Stats
Constants ¶
const ( // DefaultCacheDir is the default directory name for the cache. DefaultCacheDir = ".cache/art-dupl" // CacheVersion is incremented when cache format changes. CacheVersion = 2 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
FileCache provides caching for parsed AST nodes.
func NewFileCache ¶
NewFileCache creates a new FileCache. If cacheDir is empty, uses DefaultCacheDir.
func (*FileCache) Get ¶
Get retrieves cached AST nodes for the given content hash. Returns the nodes and true if found (cache hit), nil and false otherwise.
func (*FileCache) Prune ¶ added in v0.4.0
Prune removes the oldest cache entries until the cache contains at most maxEntries files. Entries are evicted by modification time (oldest first). If maxEntries <= 0, no pruning occurs.