filecache

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package filecache stores fetched full-file contents (the context view's raw material) under the XDG cache directory. Entries are keyed by content identity — a git blob hash, or a PR head commit plus path — so a file that changes upstream simply produces a new key and the stale entry ages out; nothing ever needs to be invalidated in place.

Index

Constants

View Source
const (
	MaxAge   = 14 * 24 * time.Hour
	MaxBytes = 50 << 20 // 50 MiB
)

Cleanup limits. Both are enforced on every Open: entries older than MaxAge are dropped, then the oldest survivors are dropped until the total is under MaxBytes — whichever constraint bites first, bites.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a directory of content-addressed files.

func Open

func Open() (*Cache, error)

Open resolves the default cache directory ($XDG_CACHE_HOME/leanreview/files, ~/.cache fallback) and runs cleanup. Errors are returned rather than tolerated: a broken cache dir should disable caching loudly at the one caller, not fail on every Put.

func OpenAt

func OpenAt(dir string) (*Cache, error)

OpenAt opens (creating if needed) a cache rooted at dir and runs cleanup. Split from Open so tests can point it at a temp directory.

func (*Cache) Get

func (c *Cache) Get(key string) ([]byte, bool)

Get returns the cached content for key. A hit refreshes the entry's mtime, so cleanup's age/size ordering approximates least-recently-used rather than least-recently-written.

func (*Cache) Put

func (c *Cache) Put(key string, data []byte) error

Put stores content under key, atomically (write + rename) so a crash can never leave a truncated entry that Get would serve as a real file.

Jump to

Keyboard shortcuts

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