cache

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var ErrNotFound = errors.New("cache: not found")

ErrNotFound is returned by Get when no row matches the content hash.

Functions

func FileSize

func FileSize(path string) int64

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

func HashFile(path string) (string, error)

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

func HashString(s string) string

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

func Open(path string) (*Cache, error)

Open opens or creates the cache file at path. Applies schema + WAL pragmas + stamps CacheVersion into cache_meta on first open.

func (*Cache) Clear

func (c *Cache) Clear() (int64, error)

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) Close

func (c *Cache) Close() error

Close releases the underlying database handle.

func (*Cache) Get

func (c *Cache) Get(contentHash string) (*Entry, error)

Get fetches the cache entry by content hash. Returns ErrNotFound if absent.

func (*Cache) Has

func (c *Cache) Has(contentHash string) bool

Has reports whether an entry for contentHash exists.

func (*Cache) IterateAll

func (c *Cache) IterateAll(fn func(*Entry) error) error

IterateAll yields every cached entry in deterministic order (sorted by path then content_hash) — used by phase 2's enrich.

func (*Cache) List

func (c *Cache) List(limit, offset int) ([]ListEntry, error)

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

func (c *Cache) LookupByHashOrPath(query string) (*Entry, error)

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

func (c *Cache) Put(e *Entry) error

Put stores or replaces the cache entry. Atomic — all rows for the hash are wiped first then re-inserted in a single transaction.

func (*Cache) Stats

func (c *Cache) Stats() (Stats, error)

Stats returns the row counts and file-size of the cache database.

func (*Cache) Version

func (c *Cache) Version() (int, error)

Version reads the cache_version row.

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`.

type Stats

type Stats struct {
	FileCount int   `json:"file_count"`
	NodeCount int   `json:"node_count"`
	EdgeCount int   `json:"edge_count"`
	SizeBytes int64 `json:"size_bytes"`
	Version   int   `json:"version"`
}

Stats summarises the cache contents — used by `codeiq cache info`.

Jump to

Keyboard shortcuts

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