memory

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is a thread-safe in-memory implementation of store.Store.

Suitable for:

  • Development and testing
  • Small-scale deployments
  • Ephemeral data that doesn't need persistence

Performance optimizations:

  • Uses sync.RWMutex for efficient read-heavy workloads
  • Object pooling with sync.Pool to reduce GC pressure
  • Optimized lock granularity to minimize write lock duration
  • Inverted index for O(1) metadata-based search queries

func New

func New() *Store

New creates a new in-memory store.

func (*Store) Clear

func (s *Store) Clear(ctx context.Context, namespace []string) error

Clear removes all values within a namespace.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, namespace []string, key string) error

Delete removes a value by namespace and key. Returns the old value to the object pool.

func (*Store) Get

func (s *Store) Get(ctx context.Context, namespace []string, key string) (*store.Value, error)

Get retrieves a value by namespace and key.

func (*Store) List

func (s *Store) List(ctx context.Context, namespace []string) ([]string, error)

List returns all keys within a namespace.

func (*Store) Namespaces

func (s *Store) Namespaces() []string

Namespaces returns all namespace keys currently in the store.

func (*Store) Put

func (s *Store) Put(ctx context.Context, namespace []string, key string, value interface{}) error

Put stores a value with the given namespace and key. Optimizations:

  • Uses object pool to reduce allocations
  • Minimizes write lock duration by preparing data outside critical section

func (*Store) Search

func (s *Store) Search(ctx context.Context, namespace []string, filter map[string]interface{}) ([]*store.Value, error)

Search finds values matching the filter within a namespace. Optimization: Uses inverted index for O(1) lookup when filter is provided, falling back to linear scan only when no filter is specified.

func (*Store) Size

func (s *Store) Size() int

Size returns the total number of values across all namespaces.

Jump to

Keyboard shortcuts

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