cache

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTTL = 7 * 24 * time.Hour
View Source
const SchemaVersion = 1

Variables

This section is empty.

Functions

func Compute

func Compute(args ComputeArgs) string

Compute returns the deterministic SHA-256 key (lowercase hex) for the cache lookup. The schema version is folded in so a future bump invalidates every existing entry without touching disk.

func EnsureGitignore

func EnsureGitignore(repoRoot string) (bool, error)

EnsureGitignore appends `.commitbrief/` to the repo's .gitignore if not already present. Idempotent: a file that already contains the entry is left untouched. Returns true if the file was modified.

Types

type Cache

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

func Open

func Open(opts Options) (*Cache, error)

func (*Cache) Delete

func (c *Cache) Delete(key string) error

func (*Cache) Dir

func (c *Cache) Dir() string

func (*Cache) Get

func (c *Cache) Get(key string) (Entry, bool)

func (*Cache) Put

func (c *Cache) Put(key string, entry Entry) error

type ComputeArgs

type ComputeArgs struct {
	Diff         string
	SystemPrompt string
	Provider     string
	Model        string
	Lang         string
}

type Entry

type Entry struct {
	Version   int       `json:"version"`
	CreatedAt time.Time `json:"created_at"`
	TTL       int64     `json:"ttl"`
	Key       KeyMeta   `json:"key"`
	Result    Result    `json:"result"`
}

func (Entry) Expired

func (e Entry) Expired() bool

func (Entry) ExpiredAt

func (e Entry) ExpiredAt(now time.Time) bool

type KeyMeta

type KeyMeta struct {
	DiffHash         string `json:"diff_hash"`
	SystemPromptHash string `json:"system_prompt_hash"`
	Model            string `json:"model"`
	Provider         string `json:"provider"`
	Lang             string `json:"lang"`
}

type Options

type Options struct {
	Dir string

	// RepoRoot, if non-empty, enables auto-add of `.commitbrief/` to the
	// repo's .gitignore on the first successful Put.
	RepoRoot string

	// TTL controls how long an entry is considered fresh. Zero falls back
	// to DefaultTTL (7 days).
	TTL time.Duration

	// Now overrides time.Now (test injection); production callers leave it nil.
	Now func() time.Time
}

type Result

type Result struct {
	Content string `json:"content"`
	Tokens  Tokens `json:"tokens"`
}

type Tokens

type Tokens struct {
	Input  int `json:"input"`
	Output int `json:"output"`
	Cached int `json:"cached"`
}

Jump to

Keyboard shortcuts

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