memory

package
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package memory Is a copy of the storage memory from the external storage packet as a purpose to test the behavior in the unittests when using a storages from these packets

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	GCInterval: 10 * time.Second,
}

ConfigDefault is the default config

Functions

This section is empty.

Types

type Config

type Config struct {
	// Time before deleting expired keys
	//
	// Default is 10 * time.Second
	GCInterval time.Duration
}

Config defines the config for storage.

type Entry

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

Entry represents a value stored in memory along with its expiration.

type Storage

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

Storage provides an in-memory implementation of the storage interface for testing purposes. Storage is safe for concurrent use, except when callers keep using the live map returned by Conn. Access to that map requires external synchronization.

func New

func New(config ...Config) *Storage

New creates a new memory storage.

func (*Storage) Close

func (s *Storage) Close() error

Close stops the background garbage collector and releases resources associated with the storage instance. It blocks until the GC goroutine has exited and is safe to call multiple times from any number of goroutines.

func (*Storage) Conn

func (s *Storage) Conn() map[string]Entry

Conn returns the underlying storage map. The returned map remains shared with the storage, so callers must not modify it and must synchronize any access that overlaps with other storage operations.

func (*Storage) Delete

func (s *Storage) Delete(key string) error

Delete removes the value stored for key.

func (*Storage) DeleteWithContext

func (s *Storage) DeleteWithContext(ctx context.Context, key string) error

DeleteWithContext removes the value for the given key while honoring context cancellation.

func (*Storage) Get

func (s *Storage) Get(key string) ([]byte, error)

Get returns the stored value for key, ignoring missing or expired entries by returning nil.

func (*Storage) GetWithContext

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

GetWithContext retrieves the value for the given key while honoring context cancellation.

func (*Storage) Keys

func (s *Storage) Keys() ([][]byte, error)

Keys returns all keys stored in the memory storage.

func (*Storage) Reset

func (s *Storage) Reset() error

Reset clears all keys and values from the storage map.

func (*Storage) ResetWithContext

func (s *Storage) ResetWithContext(ctx context.Context) error

ResetWithContext clears all stored keys while honoring context cancellation.

func (*Storage) Set

func (s *Storage) Set(key string, val []byte, exp time.Duration) error

Set saves val under key and schedules it to expire after exp. A zero exp keeps the entry indefinitely.

func (*Storage) SetWithContext

func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error

SetWithContext sets the value for the given key while honoring context cancellation.

Jump to

Keyboard shortcuts

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