cache

package
v0.6.16 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package cache manages the local graph cache stored under ~/.supermodel/cache/. Graphs are keyed by the SHA-256 hash of the uploaded repository ZIP, matching the content-addressed scheme used by the Supermodel API.

This is a shared kernel package. It must contain no business logic. Slice packages under internal/ may import it freely.

Index

Constants

View Source
const DefaultTTL = 30 * 24 * time.Hour

DefaultTTL is how long cached entries are considered fresh.

Variables

This section is empty.

Functions

func AnalysisKey added in v0.4.0

func AnalysisKey(fingerprint, analysisType, version string) string

AnalysisKey builds a cache key for a specific analysis type on a repo state. version is the CLI version string and is included so the cache is invalidated automatically after an upgrade.

func Evict

func Evict(hash string) error

Evict removes the cached entry for hash. No-ops on cache miss.

func Get

func Get(hash string) (*api.Graph, error)

Get loads a cached graph for hash. Returns (nil, nil) on cache miss or expiry.

func GetJSON added in v0.4.1

func GetJSON(hash string, v any) (bool, error)

GetJSON reads the cached JSON for hash and unmarshals it into v. Returns (true, nil) on hit, (false, nil) on miss, (false, err) on error.

func HashFile

func HashFile(path string) (string, error)

HashFile returns the hex-encoded SHA-256 of the file at path.

func NewestEntry added in v0.6.0

func NewestEntry() time.Time

NewestEntry returns the modification time of the most recently written cache entry, or the zero time if the cache is empty.

func Prune added in v0.6.0

func Prune(maxAge time.Duration) (int, error)

Prune removes cache entries older than maxAge. Returns the number removed.

func Put

func Put(hash string, g *api.Graph) error

Put stores g in the cache under hash.

func PutJSON added in v0.4.1

func PutJSON(hash string, v any) error

PutJSON serialises v as JSON and stores it under hash. Unlike Put, it works with any value type — useful for dead-code and blast-radius results.

func RepoFingerprint added in v0.4.0

func RepoFingerprint(dir string) (string, error)

RepoFingerprint returns a fast, content-based cache key for the repo at dir.

For clean git repos (~1ms): returns the commit SHA. For dirty git repos (~100ms): returns commitSHA:dirtyHash. For non-git dirs: returns empty string and an error.

func Stats added in v0.6.0

func Stats() (count int, sizeBytes int64)

Stats returns aggregate cache metrics: entry count and total size in bytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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