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 CacheKey(content []byte) stringdeprecated
- func Key(content []byte) string
- type FileCache
- func (fc *FileCache) Clear() error
- func (fc *FileCache) Get(contentHash string) ([]*syntax.Node, bool)
- func (fc *FileCache) GetStats() (int64, int64)
- func (fc *FileCache) Has(contentHash string) bool
- 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 ¶
View Source
const ( // DefaultCacheDir is the default directory name for the cache. DefaultCacheDir = ".cache/art-dupl" // CacheVersion is incremented when cache format changes. CacheVersion = 1 )
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.
Click to show internal directories.
Click to hide internal directories.