storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

Functions

This section is empty.

Types

type Memory

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

Memory is a concurrent, process-local Storage. Its zero value is ready for use.

func (*Memory) Delete

func (m *Memory) Delete(ctx context.Context, key string) error

Delete removes key and returns nil when it is absent.

If ctx is already done, Delete returns ctx.Err without changing storage.

func (*Memory) Get

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

Get returns an independent copy of the value associated with key.

It returns ErrKeyNotFound when the key is missing or expired. If ctx is already done, Get returns ctx.Err without reading storage.

func (*Memory) Set

func (m *Memory) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error

Set replaces key with a copy of value.

A positive expiration removes the value after that duration, while a zero or negative expiration keeps it until it is replaced or deleted. If ctx is already done, Set returns ctx.Err without changing storage.

type Storage

type Storage interface {
	// Get returns the value associated with key.
	//
	// A missing or expired key must return an error that matches ErrKeyNotFound with errors.Is.
	Get(ctx context.Context, key string) ([]byte, error)

	// Set stores value under key and replaces any existing value.
	//
	// A positive expiration sets a time to live, while a zero or negative expiration keeps the value until it is replaced or deleted.
	Set(ctx context.Context, key string, value []byte, expiration time.Duration) error

	// Delete removes key and returns nil when it is absent.
	Delete(ctx context.Context, key string) error
}

Storage persists opaque session state and must be safe for concurrent use.

Implementations do not need compare-and-swap or distributed locking because a Bus serializes updates locally.

func NewMemory

func NewMemory() Storage

NewMemory returns an empty, process-local Storage.

Jump to

Keyboard shortcuts

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