memory

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMaxCost is returned when MaxCost is <= 0.
	ErrInvalidMaxCost = errors.New("memory: MaxCost must be > 0")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxCost is the maximum cache size in bytes (REQUIRED, must be > 0).
	MaxCost int64

	// NumCounters is the number of TinyLFU counters (OPTIONAL).
	// Default: 10 * MaxCost (recommended for good hit ratio).
	NumCounters int64

	// BufferItems is the size of the async buffer (OPTIONAL).
	// Default: 64
	BufferItems int64

	// Metrics enables metrics collection (OPTIONAL).
	// Default: false
	Metrics bool
}

Config holds configuration for MemoryStore.

Reference: .references/ristretto/cache.go (Config struct)

type MemoryStore

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

MemoryStore is an in-memory cache store backed by Ristretto. Thread-safe for concurrent use.

Reference: .references/ristretto/cache.go (Cache[K,V] with TinyLFU)

func New

func New(cfg Config) (*MemoryStore, error)

New creates a new MemoryStore with the given configuration.

Reference: .references/ristretto/cache.go (NewCache function)

func (*MemoryStore) Clear

func (s *MemoryStore) Clear(ctx context.Context) error

Clear removes all entries from the cache.

Reference: .references/ristretto/cache.go (Clear method)

func (*MemoryStore) Close

func (s *MemoryStore) Close() error

Close releases resources associated with the cache. Idempotent - safe to call multiple times.

Reference: .references/ristretto/cache.go (Close method)

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(ctx context.Context, key string) error

Delete removes a value from the cache. Idempotent - deleting a non-existent key returns nil.

Reference: .references/ristretto/cache.go (Del method)

func (*MemoryStore) Get

func (s *MemoryStore) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves a value from the cache by key. Returns cache.ErrNotFound if the key doesn't exist or has expired.

Reference: .references/ristretto/cache.go (Get method)

func (*MemoryStore) Set

func (s *MemoryStore) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set stores a value in the cache with the specified TTL.

TTL semantics: - ttl == 0: no expiration (lives until evicted) - ttl < 0: no expiration (lives until evicted) - ttl > 0: expires after the specified duration

Reference: .references/ristretto/cache.go (SetWithTTL method)

func (*MemoryStore) Wait

func (s *MemoryStore) Wait()

Wait blocks until all pending Set operations have been processed by Ristretto's internal buffers. Useful in tests to ensure consistency after Set calls.

Jump to

Keyboard shortcuts

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