Documentation
¶
Overview ¶
Package cache provides LRU blob caching with Bloom pre-filter and cost-based eviction.
Index ¶
- Constants
- type LRUBlobCache
- func (c *LRUBlobCache) CacheHits() int64
- func (c *LRUBlobCache) CacheMisses() int64
- func (c *LRUBlobCache) Clear()
- func (c *LRUBlobCache) Get(hash gitlib.Hash) *gitlib.CachedBlob
- func (c *LRUBlobCache) GetMulti(hashes []gitlib.Hash) (found map[gitlib.Hash]*gitlib.CachedBlob, missing []gitlib.Hash)
- func (c *LRUBlobCache) Put(hash gitlib.Hash, blob *gitlib.CachedBlob)
- func (c *LRUBlobCache) PutMulti(blobs map[gitlib.Hash]*gitlib.CachedBlob)
- func (c *LRUBlobCache) PutMultiOwned(blobs map[gitlib.Hash]*gitlib.CachedBlob)
- func (c *LRUBlobCache) Stats() LRUStats
- type LRUStats
Constants ¶
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.