cache

package
v0.0.0-...-ffc4fba Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 2 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

This section is empty.

Functions

This section is empty.

Types

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