cache

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cache provides LRU blob caching with Bloom pre-filter and cost-based eviction.

Index

Constants

View Source
const DefaultLRUCacheSize = 256 * 1024 * 1024

DefaultLRUCacheSize is the default maximum memory size for the LRU blob cache (256 MB).

Variables

View Source
var ErrCacheCorrupt = errors.New("cache metadata corrupt")

ErrCacheCorrupt is returned when the cache metadata file cannot be parsed.

View Source
var ErrCacheNotFound = errors.New("cache metadata not found")

ErrCacheNotFound is returned when the cache metadata file does not exist.

Functions

func IsStale

func IsStale(meta IncrementalMeta, currentRootSHA string) bool

IsStale returns true when the cached root SHA does not match the current root SHA, indicating a force-push or history rewrite.

func Key

func Key(rootSHA, branch string) string

Key produces a deterministic directory name from root SHA and branch. The key is a SHA-256 hash of "rootSHA:branch", hex-encoded.

func WriteMeta

func WriteMeta(dir string, meta IncrementalMeta) error

WriteMeta atomically writes cache metadata as indented JSON to dir/cache.json.

Types

type IncrementalMeta

type IncrementalMeta struct {
	Version     int       `json:"version"`
	HeadSHA     string    `json:"head_sha"`
	Branch      string    `json:"branch"`
	RootSHA     string    `json:"root_sha"`
	CommitCount int       `json:"commit_count"`
	AnalyzerIDs []string  `json:"analyzer_ids"`
	Timestamp   time.Time `json:"timestamp"`
}

IncrementalMeta holds metadata for an incremental analysis cache.

func ReadMeta

func ReadMeta(dir string) (IncrementalMeta, error)

ReadMeta reads and parses cache metadata from dir/cache.json. Returns ErrCacheNotFound if the file does not exist. Returns ErrCacheCorrupt if the file cannot be parsed.

type LRUBlobCache

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

LRUBlobCache provides a cross-commit LRU cache for blob data. It tracks memory usage and evicts least recently used entries when the limit is exceeded. A Bloom filter pre-filters Get/GetMulti lookups to skip lock acquisition for definite misses.

func NewLRUBlobCache

func NewLRUBlobCache(maxSize int64) *LRUBlobCache

NewLRUBlobCache creates a new LRU blob cache with the specified maximum size in bytes. A Bloom filter is initialized to pre-filter lookups, sized for the estimated element count.

func (*LRUBlobCache) CacheHits

func (c *LRUBlobCache) CacheHits() int64

CacheHits returns the total cache hit count (atomic, lock-free).

func (*LRUBlobCache) CacheMisses

func (c *LRUBlobCache) CacheMisses() int64

CacheMisses returns the total cache miss count (atomic, lock-free).

func (*LRUBlobCache) Clear

func (c *LRUBlobCache) Clear()

Clear removes all entries from the cache and resets the Bloom filter.

func (*LRUBlobCache) Get

func (c *LRUBlobCache) Get(hash gitlib.Hash) *gitlib.CachedBlob

Get retrieves a blob from the cache. Returns nil if not found. Uses a Bloom filter to skip lock acquisition for definite cache misses.

func (*LRUBlobCache) GetMulti

func (c *LRUBlobCache) GetMulti(hashes []gitlib.Hash) (found map[gitlib.Hash]*gitlib.CachedBlob, missing []gitlib.Hash)

GetMulti retrieves multiple blobs from the cache. Returns a map of found blobs and a slice of missing hashes.

func (*LRUBlobCache) Put

func (c *LRUBlobCache) Put(hash gitlib.Hash, blob *gitlib.CachedBlob)

Put adds a blob to the cache. If the cache exceeds maxSize, entries are evicted using size-aware eviction (large, infrequently accessed items evicted first).

func (*LRUBlobCache) PutMulti

func (c *LRUBlobCache) PutMulti(blobs map[gitlib.Hash]*gitlib.CachedBlob)

PutMulti adds multiple blobs to the cache.

func (*LRUBlobCache) PutMultiOwned

func (c *LRUBlobCache) PutMultiOwned(blobs map[gitlib.Hash]*gitlib.CachedBlob)

PutMultiOwned adds multiple blobs without cloning. The caller guarantees the blobs are exclusively owned heap copies (not arena-backed).

func (*LRUBlobCache) Stats

func (c *LRUBlobCache) Stats() LRUStats

Stats returns cache statistics.

type LRUStats

type LRUStats = lru.Stats

LRUStats is an alias for lru.Stats.

Jump to

Keyboard shortcuts

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