Documentation
¶
Index ¶
- type BlobMemoryCache
- func (c *BlobMemoryCache) Add(entry *MemoryEntry) bool
- func (c *BlobMemoryCache) Get(name string) *MemoryEntry
- func (c *BlobMemoryCache) GetExpiredEntries(now time.Time, ttl time.Duration) []string
- func (c *BlobMemoryCache) ListNames() []string
- func (c *BlobMemoryCache) NumEntries() int
- func (c *BlobMemoryCache) ReleaseReservation(size uint64)
- func (c *BlobMemoryCache) Remove(name string)
- func (c *BlobMemoryCache) RemoveBatch(names []string)
- func (c *BlobMemoryCache) TotalBytes() uint64
- func (c *BlobMemoryCache) TryReserve(size uint64) bool
- type BlobMemoryCacheConfig
- type LRUCache
- type MemoryEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlobMemoryCache ¶ added in v0.1.13
type BlobMemoryCache struct {
// contains filtered or unexported fields
}
BlobMemoryCache provides a simple in-memory cache for blob data with capacity management. It uses RWMutex for optimal concurrent access patterns.
func NewBlobMemoryCache ¶ added in v0.1.13
func NewBlobMemoryCache( config BlobMemoryCacheConfig, stats tally.Scope, ) *BlobMemoryCache
NewBlobMemoryCache creates a new BlobMemoryCache with the specified configuration.
func (*BlobMemoryCache) Add ¶ added in v0.1.13
func (c *BlobMemoryCache) Add(entry *MemoryEntry) bool
Add attempts to add an entry to the memory cache. NOTE: TryReserve must have succeeded, else unexpected behavior will happen This operation uses a write lock for exclusive access.
func (*BlobMemoryCache) Get ¶ added in v0.1.13
func (c *BlobMemoryCache) Get(name string) *MemoryEntry
Get retrieves an entry from the memory cache. Returns nil if not present. This operation uses a read lock, allowing concurrent access.
func (*BlobMemoryCache) GetExpiredEntries ¶ added in v0.1.13
GetExpiredEntries returns names of entries older than TTL. Uses RLock for minimal contention (allows concurrent reads).
func (*BlobMemoryCache) ListNames ¶ added in v0.1.13
func (c *BlobMemoryCache) ListNames() []string
ListNames returns all entry names in the cache.
func (*BlobMemoryCache) NumEntries ¶ added in v0.1.13
func (c *BlobMemoryCache) NumEntries() int
NumEntries returns the current number of entries in the cache.
func (*BlobMemoryCache) ReleaseReservation ¶ added in v0.1.13
func (c *BlobMemoryCache) ReleaseReservation(size uint64)
ReleaseReservation releases previously reserved space. This is called when a reservation won't be used (e.g., download failed, entry already exists).
func (*BlobMemoryCache) Remove ¶ added in v0.1.13
func (c *BlobMemoryCache) Remove(name string)
Remove removes an entry from the memory cache. No-op if entry is not present. This operation uses a write lock for exclusive access.
func (*BlobMemoryCache) RemoveBatch ¶ added in v0.1.13
func (c *BlobMemoryCache) RemoveBatch(names []string)
RemoveBatch removes multiple entries atomically. Uses Lock for batch deletion (single lock acquisition for entire batch).
func (*BlobMemoryCache) TotalBytes ¶ added in v0.1.13
func (c *BlobMemoryCache) TotalBytes() uint64
TotalBytes returns the current total size in bytes.
func (*BlobMemoryCache) TryReserve ¶ added in v0.1.13
func (c *BlobMemoryCache) TryReserve(size uint64) bool
TryReserve attempts to reserve space for buffering before adding to cache. Returns true if space was reserved, false if insufficient space. Reservation is tracked in totalSize to prevent OOM conditions.
type BlobMemoryCacheConfig ¶ added in v0.1.13
type BlobMemoryCacheConfig struct {
MaxSize uint64 // Maximum memory in bytes
}
BlobMemoryCacheConfig defines configuration for BlobMemoryCache.
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
LRUCache provides a simple LRU cache with both size and TTL limits. It uses RWMutex for optimal concurrent access patterns - multiple concurrent reads are allowed while writes get exclusive access.
func NewLRUCache ¶
NewLRUCache creates a new LRU cache with the specified maximum size and TTL.
func (*LRUCache) Add ¶
Add marks a key as cached. This operation uses a write lock for exclusive access. If the key already exists, its expiration time is updated and it's moved to the end of the LRU order. If the cache exceeds maxSize, oldest entries are evicted.
type MemoryEntry ¶ added in v0.1.13
MemoryEntry represents a blob stored in memory cache.
func (*MemoryEntry) Size ¶ added in v0.1.13
func (m *MemoryEntry) Size() uint64
Size returns the size of the data in MemoryEntry