store

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KindLabel

func KindLabel(k Kind) string

KindLabel returns a human-readable label for a Kind.

Types

type FileStore

type FileStore struct {
	// contains filtered or unexported fields
}

FileStore is a file-backed implementation of Store.

Layout under root:

{root}/{kind}/{fileHash[:2]}/{fileHash[2:]}-{ruleSetHash}.bin

Two-level sharding on the file-content hash keeps no single directory larger than 256 children even in large repos. The ruleSetHash suffix allows the same source file to have independent entries for different rule configurations.

func New

func New(dir string) *FileStore

New returns a FileStore rooted at dir. The directory is created on the first Put call; New itself does no I/O.

func (*FileStore) Get

func (s *FileStore) Get(key Key) ([]byte, bool)

Get retrieves a cached value. Returns (nil, false) on any miss or I/O error.

func (*FileStore) Invalidate

func (s *FileStore) Invalidate(ruleIDs ...string) error

Invalidate removes entries from the store. With no arguments it clears everything. With ruleIDs it removes every entry whose filename contains any of the given IDs as a substring of the ruleSetHash hex.

Note: in Phase 0 the ruleSetHash is an opaque hash; per-rule targeting requires rule metadata to embed rule checksums so each rule ID maps to a deterministic ruleSetHash prefix. Until that lands, passing any ruleIDs clears the whole store (conservative but always correct).

func (*FileStore) Put

func (s *FileStore) Put(key Key, value []byte) error

Put stores value at key, atomically replacing any prior entry.

func (*FileStore) Stats

func (s *FileStore) Stats() (Stats, error)

Stats returns entry count and total byte size by walking the store root, broken down by Kind (the top-level directory name encodes the kind).

type Key

type Key struct {
	FileHash    [32]byte
	RuleSetHash [16]byte
	Kind        Kind
}

Key uniquely identifies one entry in the store.

FileHash is the full SHA-256 of the source file's bytes. RuleSetHash encodes the active rule IDs and their configuration (16 bytes). Kind scopes the entry to its owning subsystem so KindIncremental and KindOracle entries for the same file never collide.

type Kind

type Kind uint8

Kind distinguishes the logical cache domain inside a unified store.

const (
	KindIncremental Kind = iota // incremental analysis findings
	KindOracle                  // JVM type-analysis results
	KindMatrix                  // experiment matrix baseline counts
	KindBaseline                // baseline suppression membership
)

type KindStats

type KindStats struct {
	EntryCount int
	TotalBytes int64
}

KindStats holds entry count and byte size for one Kind.

type Stats

type Stats struct {
	EntryCount int
	TotalBytes int64
	HitRate    float64            // populated by callers that track hits/misses
	ByKind     map[Kind]KindStats // per-kind breakdown
}

Stats summarises utilisation for krit cache stats.

type Store

type Store interface {
	// Get retrieves a cached value by key. Returns (nil, false) on miss.
	Get(key Key) ([]byte, bool)

	// Put stores a value, overwriting any existing entry for the key.
	Put(key Key, value []byte) error

	// Invalidate removes all entries whose on-disk path encodes one of
	// the given rule IDs in their RuleSetHash prefix directory. This is
	// a best-effort scan; it never returns an error for individual
	// missing entries.
	Invalidate(ruleIDs ...string) error

	// Stats returns a point-in-time summary of cache utilisation.
	Stats() (Stats, error)
}

Store is a content-hash-keyed byte store. Each subsystem encodes its own payload into []byte; the store owns only persistence and invalidation.

Jump to

Keyboard shortcuts

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