{"modulePath":"github.com/CommitBrief/commitbrief","version":"v1.23.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cache\n\n## Constants\n\n```go\nconst (\n\tFormatJSON             = \"json\"\n\tFormatMarkdownFallback = \"markdown-fallback\"\n\t// FormatPlainText is the marker for cache entries written by\n\t// PlainTextEmitter providers (CLI-based). The Content is the\n\t// host CLI's already-formatted output — no JSON parse, no\n\t// retry-once, no degrade warning. Renderer emits Content verbatim.\n\tFormatPlainText = \"plain-text\"\n)\n```\nFormat values for cache.Result.Format. Kept as package-level constants so callers (CLI, renderer) avoid stringly-typed comparisons.\n\n```go\nconst DefaultTTL = 7 * 24 * time.Hour\n```\n\n```go\nconst SchemaVersion = 1\n```\n\n## Functions\n\n```go\nfunc Compute(args ComputeArgs) string\n```\nCompute 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.\n\n```go\nfunc EnsureGitignore(repoRoot string) (bool, error)\n```\nEnsureGitignore 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.\n\n## Types\n\n```go\ntype Cache struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc Open(opts Options) (*Cache, error)\n```\n\n```go\nfunc (c *Cache) Delete(key string) error\n```\n\n```go\nfunc (c *Cache) Dir() string\n```\n\n```go\nfunc (c *Cache) Get(key string) (Entry, bool)\n```\n\n```go\nfunc (c *Cache) Put(key string, entry Entry) error\n```\n\n```go\ntype ComputeArgs struct {\n\tDiff         string\n\tSystemPrompt string\n\tProvider     string\n\tModel        string\n\tLang         string\n\n\t// WithContext marks a --with-context run (ADR-0017). A context run and\n\t// a diff-only run on the same diff must not alias, so when true a\n\t// marker is folded into the key. When false NOTHING extra is written,\n\t// keeping diff-only keys byte-identical to pre-ADR-0017 entries — no\n\t// mass cache invalidation on upgrade.\n\tWithContext bool\n\n\t// Mode namespaces non-review cache entries (e.g. \"commit\" for the\n\t// commit-message generation, ADR-0019). The commit system prompt\n\t// already differs from the review prompt, so collision is unlikely;\n\t// the explicit marker makes the separation impossible. Folded in only\n\t// when non-empty, so review keys stay byte-identical to before.\n\tMode string\n}\n```\n\n```go\ntype Entry struct {\n\tVersion   int       `json:\"version\"`\n\tCreatedAt time.Time `json:\"created_at\"`\n\tTTL       int64     `json:\"ttl\"`\n\tKey       KeyMeta   `json:\"key\"`\n\tResult    Result    `json:\"result\"`\n}\n```\n\n```go\nfunc (e Entry) Expired() bool\n```\n\n```go\nfunc (e Entry) ExpiredAt(now time.Time) bool\n```\n\n```go\ntype KeyMeta struct {\n\tDiffHash         string `json:\"diff_hash\"`\n\tSystemPromptHash string `json:\"system_prompt_hash\"`\n\tModel            string `json:\"model\"`\n\tProvider         string `json:\"provider\"`\n\tLang             string `json:\"lang\"`\n}\n```\n\n```go\ntype Options struct {\n\tDir string\n\n\t// RepoRoot, if non-empty, enables auto-add of `.commitbrief/` to the\n\t// repo's .gitignore on the first successful Put.\n\tRepoRoot string\n\n\t// TTL controls how long an entry is considered fresh. Zero falls back\n\t// to DefaultTTL (7 days).\n\tTTL time.Duration\n\n\t// MaxSizeBytes bounds the on-disk cache size. After each successful\n\t// Put, if the cache directory exceeds this many bytes, the oldest\n\t// entries (by CreatedAt, mtime fallback) are evicted oldest-first\n\t// until the total fits — see eviction.go. Zero or negative disables\n\t// eviction (unlimited; the manual `cache prune` stays the stand-in).\n\t// The just-written entry is never evicted, so a single entry larger\n\t// than the cap survives.\n\tMaxSizeBytes int64\n\n\t// Now overrides time.Now (test injection); production callers leave it nil.\n\tNow func() time.Time\n}\n```\n\n```go\ntype Result struct {\n\tContent string `json:\"content\"`\n\tTokens  Tokens `json:\"tokens\"`\n\n\t// Format records which renderer path the cached entry should take on\n\t// replay. Values (ADR-0014 §4):\n\t//   \"json\"               — Content is the structured-findings JSON; the\n\t//                          renderer parses it as usual.\n\t//   \"markdown-fallback\"  — provider produced unparseable output; the\n\t//                          retry also failed. The cached Content is the\n\t//                          raw text and the renderer skips the parse\n\t//                          step entirely (no warning re-emitted).\n\t// Empty string is treated as \"json\" for backwards compatibility with\n\t// pre-ADR-0014 cache entries; they'll be invalidated next request\n\t// anyway via the system-prompt SHA change (ADR-0014 §6).\n\tFormat string `json:\"format,omitempty\"`\n\n\t// DegradeReason is the stable snake-case reason (ADR-0031) a\n\t// \"markdown-fallback\" entry was written with, so a cache replay can stamp\n\t// meta.degrade_reason exactly as the live call did. Empty for every other\n\t// format, and for fallback entries written before this field existed (the\n\t// replay then derives a reason from Content). Not a cache-key input.\n\tDegradeReason string `json:\"degrade_reason,omitempty\"`\n}\n```\n\n```go\ntype Tokens struct {\n\tInput  int `json:\"input\"`\n\tOutput int `json:\"output\"`\n\tCached int `json:\"cached\"`\n}\n```\n\n","path":"github.com/CommitBrief/commitbrief/internal/cache","name":"cache","synopsis":"","isRedistributable":true}
