Documentation
¶
Index ¶
- Constants
- Variables
- func FileSize(path string) int64
- func HashFile(path string) (string, error)
- func HashString(s string) string
- type Cache
- func (c *Cache) Clear() (int64, error)
- func (c *Cache) Close() error
- func (c *Cache) Get(contentHash string) (*Entry, error)
- func (c *Cache) Has(contentHash string) bool
- func (c *Cache) IterateAll(fn func(*Entry) error) error
- func (c *Cache) List(limit, offset int) ([]ListEntry, error)
- func (c *Cache) LookupByHashOrPath(query string) (*Entry, error)
- func (c *Cache) Put(e *Entry) error
- func (c *Cache) Stats() (Stats, error)
- func (c *Cache) Version() (int, error)
- type Entry
- type ListEntry
- type Stats
Constants ¶
const CacheVersion = 6
CacheVersion is bumped whenever the hash algorithm, schema, or any field shape changes. Java side is currently version 5. Go side starts at 6 to force a rebuild on first run.
Variables ¶
var ErrNotFound = errors.New("cache: not found")
ErrNotFound is returned by Get when no row matches the content hash.
Functions ¶
func FileSize ¶
FileSize returns the cache file size in bytes; 0 when the file does not exist. Wrap of os.Stat — exposed as a method so callers don't need to know the cache path.
func HashFile ¶
HashFile returns the lowercase hex SHA-256 digest of the file at path. Output matches Java io.github.randomcodespace.iq.cache.FileHasher.hash — 64 hex chars, lowercase, SHA-256.
func HashString ¶
HashString returns the lowercase hex SHA-256 of s (UTF-8 bytes). Mirrors Java FileHasher.hashString.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a SQLite-backed analysis cache. Safe for concurrent reads. Writes serialize via SQLite's WAL mode + busy_timeout.
func Open ¶
Open opens or creates the cache file at path. Applies schema + WAL pragmas + stamps CacheVersion into cache_meta on first open.
func (*Cache) Clear ¶
Clear truncates every row from files / nodes / edges. The cache_meta row (cache version) is preserved so re-opens don't trigger a version mismatch. Returns the number of rows deleted from `files` so callers can report progress.
func (*Cache) IterateAll ¶
IterateAll yields every cached entry in deterministic order (sorted by path then content_hash) — used by phase 2's enrich.
func (*Cache) List ¶
List returns up to `limit` summarised cache entries ordered by path. Use offset to page through the cache. Pass limit <= 0 for an unbounded scan (use carefully — large caches can have tens of thousands of rows).
func (*Cache) LookupByHashOrPath ¶
LookupByHashOrPath resolves a query against the cache: tries content hash first, then file path (full match), then file path suffix. Returns the full Entry. When no match is found, returns (nil, sql.ErrNoRows) so callers can detect not-found explicitly.
func (*Cache) Put ¶
Put stores or replaces the cache entry. Atomic — all rows for the hash are wiped first then re-inserted in a single transaction.
type Entry ¶
type Entry struct {
ContentHash string
Path string
Language string
ParsedAt string // RFC3339
Nodes []*model.CodeNode
Edges []*model.CodeEdge
}
Entry is a single file's cached detector results, keyed by content hash.
type ListEntry ¶
type ListEntry struct {
ContentHash string `json:"content_hash"`
Path string `json:"path"`
Language string `json:"language"`
ParsedAt string `json:"parsed_at"`
NodeCount int `json:"node_count"`
EdgeCount int `json:"edge_count"`
}
ListEntry is one summarised row for `codeiq cache list`.