cache

package
v0.0.0-...-1125d44 Latest Latest
Warning

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

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

Documentation

Overview

Package cache persists and restores the documentation index to avoid full rebuilds.

Index

Constants

View Source
const CacheVersion = 4

CacheVersion is incremented when the cache format changes, invalidating old caches.

Variables

This section is empty.

Functions

func CachePath

func CachePath() string

CachePath returns the default file path for the index cache.

func ComputeFingerprint

func ComputeFingerprint(entries []FileEntry) string

ComputeFingerprint returns a SHA-256 hash of sorted file entries for cache invalidation.

func InvalidateCache

func InvalidateCache() error

InvalidateCache deletes the cache file at the default path.

func ParseFileEntryKey

func ParseFileEntryKey(key string) (source, relPath string)

ParseFileEntryKey splits a cache key "source:rel/path.md" into source name and relative path.

func SaveCache

func SaveCache(idx *index.DocIndex, fingerprint string, fileResults map[string]*index.FileResult, files map[string]int64) error

SaveCache writes the index to the default cache path.

func SaveCacheTo

func SaveCacheTo(path string, idx *index.DocIndex, fingerprint string, fileResults map[string]*index.FileResult, files map[string]int64) error

SaveCacheTo writes the index to the given path. InvertedIndex and DocumentFrequency are omitted since they are cheaply rebuilt from chunk term frequencies on load.

Types

type CacheEnvelope

type CacheEnvelope struct {
	Version     int
	Fingerprint string
	CreatedAt   string
	Index       *index.DocIndex
	FileResults map[string]*index.FileResult
	Files       map[string]int64
}

CacheEnvelope wraps a cached index with per-file metadata for incremental rebuilds.

func LoadCache

func LoadCache() (*CacheEnvelope, error)

LoadCache reads the index from the default cache path.

func LoadCacheFrom

func LoadCacheFrom(path string) (*CacheEnvelope, error)

LoadCacheFrom reads the index from the given path. It rebuilds InvertedIndex and DocumentFrequency which are omitted from the cache.

type FileDiff

type FileDiff struct {
	Added    []FileEntry // files on disk but not in cache
	Modified []FileEntry // files whose mtime changed since cache was written
	Removed  []string    // keys in cache but no longer on disk
}

FileDiff describes the changes between a cached file set and the current filesystem.

func DiffEntries

func DiffEntries(cached map[string]int64, current []FileEntry) FileDiff

DiffEntries compares the cached per-file mtimes against the current file entries and returns the set of added, modified, and removed files.

func (FileDiff) ChangedCount

func (d FileDiff) ChangedCount() int

ChangedCount returns the total number of files that differ.

func (FileDiff) IsClean

func (d FileDiff) IsClean() bool

IsClean returns true when no files have changed.

type FileEntry

type FileEntry struct {
	Key     string
	MtimeMs int64
}

FileEntry records a file's path and modification time for fingerprinting.

func CollectFileEntries

func CollectFileEntries(sources []SourceInfo) ([]FileEntry, error)

CollectFileEntries walks all sources and returns their file entries for fingerprinting. It applies the same directory skip rules and ignore patterns as the indexer so the fingerprint only covers files that will actually be indexed.

type SourceInfo

type SourceInfo struct {
	Name   string
	Path   string
	Ignore []string
}

SourceInfo provides the name, path, and ignore patterns needed to collect file entries.

Jump to

Keyboard shortcuts

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