cache

package
v0.8.0-beta.26 Latest Latest
Warning

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

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

Documentation

Overview

Package cache persists per-file extraction results so `graphify update` can rebuild the graph after re-parsing only the files that changed. The expensive step is the tree-sitter parse; resolving and assembling the whole graph from cached per-file results is cheap, so caching the results (not just hashes) lets an incremental rebuild produce output byte-identical to a full build.

Index

Constants

View Source
const FileName = ".graphify_cache.json"

FileName is the cache file written under graphify-out alongside graph.json.

View Source
const StatFileName = ".graphify_stat.json"

StatFileName is the stat sidecar written alongside FileName. It lets an incremental run skip re-reading and re-hashing files whose size and mtime are unchanged — the same trade-off make(1) makes.

Variables

This section is empty.

Functions

func HashBytes

func HashBytes(b []byte) string

HashBytes returns the hex SHA-256 of b.

func Save

func Save(path string, c Cache) error

Save writes the cache as compact JSON.

func SaveStat added in v0.6.0

func SaveStat(path string, s StatIndex) error

SaveStat writes the stat sidecar as compact JSON.

Types

type Cache

type Cache map[string]Entry

Cache maps a slash-relative file path to its cached entry.

func Load

func Load(path string) Cache

Load reads a cache file. A missing or unreadable file returns an empty cache and no error, so callers can treat "no cache yet" as "re-parse everything".

type Entry

type Entry struct {
	Hash   string         `json:"hash"`
	Result extract.Result `json:"result"`
}

Entry is one file's content hash and its cached extraction result.

type StatEntry added in v0.6.0

type StatEntry struct {
	Size    int64  `json:"size"`
	MtimeNs int64  `json:"mtime_ns"`
	Hash    string `json:"hash"`
}

StatEntry records a file's size, modification time, and content hash so an unchanged file (matching size+mtime) can reuse its hash without being read.

func HashFile added in v0.6.0

func HashFile(absPath string, prev StatEntry, prevOK bool) (hash string, entry StatEntry, src []byte, ok bool)

HashFile returns the content hash of the file at absPath plus the StatEntry to persist for it, using a make(1)-style stat fastpath: when prev (the previous run's entry for this path, prevOK) matches the file's current size and mtime, its hash is reused and the file is not read; src is then nil. Otherwise the file is read and hashed, and src holds its bytes for the caller to parse. It is best-effort: a stat failure falls through to a full read. A read failure returns ok=false so the caller can skip the file.

type StatIndex added in v0.6.0

type StatIndex map[string]StatEntry

StatIndex maps a slash-relative file path to its stat fastpath entry.

func LoadStat added in v0.6.0

func LoadStat(path string) StatIndex

LoadStat reads the stat sidecar. A missing or unreadable file returns an empty index and no error, so callers fall back to reading and hashing every file.

Jump to

Keyboard shortcuts

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