cache

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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

func (c *BlobMemoryCache) GetExpiredEntries(now time.Time, ttl time.Duration) []string

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

func NewLRUCache(maxSize int, ttl time.Duration) *LRUCache

NewLRUCache creates a new LRU cache with the specified maximum size and TTL.

func (*LRUCache) Add

func (c *LRUCache) Add(key string)

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.

func (*LRUCache) Clear

func (c *LRUCache) Clear()

Clear removes all entries from the cache.

func (*LRUCache) Delete

func (c *LRUCache) Delete(key string)

Delete removes a key from the cache.

func (*LRUCache) Has

func (c *LRUCache) Has(key string) bool

Has checks if key exists and hasn't expired. This operation uses a read lock, allowing concurrent access.

func (*LRUCache) Size

func (c *LRUCache) Size() int

Size returns the current number of entries in the cache.

type MemoryEntry added in v0.1.13

type MemoryEntry struct {
	Name      string
	Data      []byte
	MetaInfo  *core.MetaInfo
	CreatedAt time.Time
}

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

Jump to

Keyboard shortcuts

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