Documentation
¶
Index ¶
- Constants
- func Clear(cacheFilePath string) error
- func ClearDir(dir string) error
- func ClearSharedCache(cacheDir string) error
- func ComputeConfigHash(ruleNames []string, cfg *config.Config, editorConfigEnabled bool) string
- func ComputeFileHash(path string) string
- func ComputeRuleHash(ruleNames []string) string
- func DefaultDir(repoDir string) string
- func FilePath(cacheDir string, scanPaths []string) string
- func NeedsReanalysis(path string, entry FileEntry) bool
- func ParseRuleSetHash(hexStr string) [16]byte
- func ResolveCacheDir(cacheDir string, scanPaths []string) (dir string, filePath string)
- type Cache
- func (c *Cache) AttachStore(s *store.FileStore, ruleSetHash [16]byte)
- func (c *Cache) CheckFiles(filePaths []string, ruleHash string, scanPaths ...string) *Result
- func (c *Cache) Prune()
- func (c *Cache) Save(cacheFilePath string) error
- func (c *Cache) SaveToDir(dir string) error
- func (c *Cache) ShouldSkipFullSaveForSmallDelta(result *Result, maxMisses int) bool
- func (c *Cache) UpdateEntryColumns(path string, columns *scanner.FindingColumns)
- type FileEntry
- type Result
- type Stats
Constants ¶
const CacheFileName = "incremental.cache"
Variables ¶
This section is empty.
Functions ¶
func ClearSharedCache ¶
ClearSharedCache removes all cache files from a shared cache directory.
func ComputeConfigHash ¶
ComputeConfigHash computes a hash from active rule names, the resolved config, and whether editorconfig is enabled. This ensures the cache is invalidated when config-derived thresholds change (e.g., MaxLineLength from editorconfig).
func ComputeFileHash ¶
ComputeFileHash computes a SHA-256 hash of the file content (truncated to 16 hex chars). Routed through the shared hashutil.Memo so a file hashed by other cache subsystems in the same run pays SHA-256 once.
func ComputeRuleHash ¶
ComputeRuleHash computes a hash from the sorted list of active rule names. This ensures cache invalidation when rules change. Deprecated: Use ComputeConfigHash for config-aware cache invalidation.
func DefaultDir ¶
DefaultDir returns Krit's repo-local incremental cache directory.
func FilePath ¶
FilePath returns the full path to the cache file for the given directory and scan paths. When cacheDir is non-empty and scanPaths are provided, the filename is derived from a hash of the scan paths to avoid collisions.
func NeedsReanalysis ¶
NeedsReanalysis checks whether a file needs to be re-analyzed. Fast path: compare modtime + size. Slow path: content hash.
func ParseRuleSetHash ¶
ParseRuleSetHash converts a 32-hex-char config hash string (from ComputeConfigHash) into the 16-byte form used in store.Key.
func ResolveCacheDir ¶
ResolveCacheDir returns the cache directory and file path to use. If cacheDir is set via --cache-dir, it is used with a hashed filename. Otherwise Krit writes under the repo-local .krit/cache directory.
Types ¶
type Cache ¶
type Cache struct {
Version string `json:"version"`
RuleHash string `json:"ruleHash"`
ScanPaths []string `json:"scanPaths,omitempty"`
Files map[string]FileEntry `json:"files"`
// contains filtered or unexported fields
}
Cache holds the entire incremental analysis cache.
func Load ¶
Load reads the cache file from the given path. Returns an empty cache if the file does not exist or is invalid.
func LoadFromDir ¶
LoadFromDir reads the cache file from the given directory (legacy API). Deprecated: Use Load with a full file path from ResolveCacheDir.
func (*Cache) AttachStore ¶
AttachStore configures c to read and write all incremental cache entries through s instead of the in-memory Files map. ruleSetHash must be the parsed form of ComputeConfigHash (use ParseRuleSetHash).
Once attached, CheckFiles consults the store; UpdateEntryColumns writes to the store; Save becomes a no-op. The existing JSON file is no longer read after AttachStore — the first warm run regenerates entries in the store.
func (*Cache) CheckFiles ¶
CheckFiles checks which files can use cached results and which need reanalysis. Returns cached findings and a set of paths that are cache hits. When scanPaths is non-empty, the cache is invalidated if the scan paths differ.
func (*Cache) Save ¶
Save writes the cache file atomically to the given path. It writes to a temporary file first, then renames for crash safety and safe concurrent access. When a store is attached, Save is a no-op because entries are persisted individually on each UpdateEntry call.
func (*Cache) SaveToDir ¶
SaveToDir writes the cache file to the given directory (legacy API). Deprecated: Use Save with a full file path from ResolveCacheDir.
func (*Cache) ShouldSkipFullSaveForSmallDelta ¶
ShouldSkipFullSaveForSmallDelta reports whether a JSON-backed cache run should avoid rewriting the full cache file after a tiny dirty worktree delta. Dirty files are still reanalyzed on the next run unless their entry was persisted elsewhere, so this trades repeated dirty-file hits for lower save latency without reusing stale findings.
func (*Cache) UpdateEntryColumns ¶
func (c *Cache) UpdateEntryColumns(path string, columns *scanner.FindingColumns)
UpdateEntryColumns updates the cache for a single file after analysis using columnar findings without reconstituting []Finding.
type FileEntry ¶
type FileEntry struct {
Hash string `json:"hash"`
ModTime int64 `json:"modTime"`
Size int64 `json:"size"`
Columns scanner.FindingColumns `json:"-"`
}
FileEntry holds cached analysis results for a single file.
func (FileEntry) MarshalJSON ¶
MarshalJSON persists the cache in columnar form.
func (*FileEntry) UnmarshalJSON ¶
UnmarshalJSON accepts both the new columnar cache encoding and the legacy findings array so older cache files still load cleanly.
type Result ¶
type Result struct {
CachedColumns scanner.FindingColumns
CachedPaths map[string]bool // paths that were cache hits
CachedHashes map[string]string
TotalCached int
TotalFiles int
GitDirtyPathsKnown bool
GitDirtyPathCount int
}
Result holds the outcome of checking files against the cache.